Connection to database : ADODB.Connection « Access « VBA / Excel / Access / Word






Connection to database

 
Sub ConnectToDatabase()
  Dim Connection As ADODB.Connection
  On Error GoTo Except
    Set Connection = New ADODB.Connection
    Connection.Provider = "Microsoft.Jet.OLEDB.4.0"
    Connection.ConnectionString = "data source=C:\nwind.mdb"
    Connection.Mode = adModeReadWrite
    Connection.Open
    MsgBox "Connected via " & Connection.Provider & " OLE DB Provider!", vbInformation
    Exit Sub
Except:
    MsgBox Err.Description, vbCritical
End Sub

 








Related examples in the same category

1.Connect to current database
2.Creating a Connection Object
3.open up a schema with a provider to look at all the database objects
4.Connect to databse through URL
5.The Errors Collection
6.Connect to database with user name and password