VBA/Excel/Access/Word/Access/Database File
Deleting a Database File
<source lang="vb">
Sub DeleteDbFile()
Dim strFile As String strFile = CurrentProject.Path & "\mydb.mdb" If Dir(strFile) <> "" Then Kill strFile MsgBox "The database file " & strFile & _ " was successfully deleted." End If
End Sub
</source>
Prompting the User for the Database Path and Name
<source lang="vb">
Sub RefreshLink()
On Error GoTo RefreshLink_Err Dim cat As ADOX.Catalog Dim tdf As ADOX.Table Dim strNewLocation As String Dim strTemp As String Set cat = New ADOX.Catalog Set cat.ActiveConnection = CurrentProject.Connection Set tdf = cat.Tables("Employees") strTemp = tdf.Columns(0).Name Exit Sub
RefreshLink_Err:
strNewLocation = InputBox("Please Enter Database Path and Name") tdf.Properties("Jet OLEDB:Link Datasource") = _ strNewLocation Set cat.ActiveConnection = CurrentProject.Connection Set tdf = cat.Tables("Employees") Resume
End Sub
</source>
The VerifyLink Routine
<source lang="vb">
Function VerifyLink() As Boolean
Dim cat As ADOX.Catalog Dim tdf As ADOX.Table Dim strTemp As String Set cat = New ADOX.Catalog With cat Set .ActiveConnection = CurrentProject.Connection On Error Resume Next For Each tdf In .Tables If tdf.Type = "LINK" Then strTemp = tdf.Columns(0).Name If Err.Number Then Exit For End If End If Next tdf End With VerifyLink = (Err.Number = 0)
End Function
</source>