VBA/Excel/Access/Word/Access/Database File — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:33, 26 мая 2010

Deleting a Database File

 
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



Prompting the User for the Database Path and Name

 
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



The VerifyLink Routine

 
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