Mega Code Archive

 
Categories / VisualBasic Script / Access
 

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