Compact and Repair Access database
step 1 : Add reference of dll
"\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\dao.dll"
Step 2 : In Button Click event write following code
Try
Dim File_Path, compact_file As String
'Original file path that u want to compact
Dim str As String = ConfigurationSettings.AppSettings("dbname")
Dim _connection_string As String = System.Windows.Forms.Application.StartupPath() & "" & str
File_Path = _connection_string
'compact file path, a temp file
compact_file = AppDomain.CurrentDomain.BaseDirectory & "db1.mdb"
'First check the file u want to compact exists or not
If File.Exists(File_Path) Then
Dim db As New dao.DBEngine()
'CompactDatabase has two parameters, creates a copy of
'compact DB at the Destination path
db.CompactDatabase(File_Path, compact_file)
End If
'restore the original file from the compacted file
If File.Exists(compact_file) Then
File.Delete(File_Path)
File.Move(compact_file, File_Path)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
File_path = " Main Database path"
Compact_file="Temp Database path for compact"
Tuesday, July 21, 2009
Wednesday, July 8, 2009
How to display combobox item or Join all combobox item with comma separate in single variable
With combobox1.Items
.Add("T1")
.Add("T2")
.Add("T3")
.Add("T4")
.Add("T5")
End With
Dim str As String
str = ""
For Each obj As Object In combobox1.Items
MsgBox(obj(0).ToString)
str = str & obj(0) & ","
Next
str = Mid(str, 1, str.Length - 1)
With combobox1.Items
.Add("T1")
.Add("T2")
.Add("T3")
.Add("T4")
.Add("T5")
End With
Dim str As String
str = ""
For Each obj As Object In combobox1.Items
MsgBox(obj(0).ToString)
str = str & obj(0) & ","
Next
str = Mid(str, 1, str.Length - 1)
Subscribe to:
Posts (Atom)