VBA/Excel/Access/Word/Access/CurrentProject Connection

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

Connecting with Microsoft Access with ADODB.Connection

 
Sub openForm()
   Dim con As ADODB.Connection
   Set con = CurrentProject.Connection
End Sub



Establishing a Connection to the Current Access Database

 
Sub Connect_ToCurrentDb()
   Dim conn As ADODB.Connection
   Dim fs As Object
   Dim txtfile As Object
   Dim I As Integer
   Set conn = CurrentProject.Connection
   Set fs = CreateObject("Scripting.FileSystemObject")
   Set txtfile = fs.CreateTextFile("C:\Propfile.txt", True)
   For I = 0 To conn.Properties.Count - 1
      Debug.Print conn.Properties(I).Name & "=" & _
          conn.Properties(I).Value
      txtfile.WriteLine (conn.Properties(I).Name & "=" & _
          conn.Properties(I).Value)
   Next I
   Debug.Print "Please check results in the " & _
       "Immediate window." & vbCrLf _
       & "The results have also been written to " _
       & "the "C:\Propfile.txt" file."
   txtfile.Close
   Set fs = Nothing
   conn.Close
   Set conn = Nothing
End Sub