22 | 02 | 2017

Connect 2 Database

  The code below allows you to connect to a Access database.

Private mobjConnAs ADODB.Connection
Private mobjCmdAs ADODB.Command

'-----------------------------------------------------------------------------
Sub ConnectToDB(Byval DatabasePath As String)
'-----------------------------------------------------------------------------

Set mobjConn = New ADODB.Connection
mobjConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" _
& Accessdatabase
mobjConn.Open

Set mobjCmd = New ADODB.Command
Set mobjCmd.ActiveConnection = mobjConn
mobjCmd.CommandType = adCmdText

End Sub

 Close the connection with the code below

'-----------------------------------------------------------------------------
Sub DisconnectFromDB()
'-----------------------------------------------------------------------------

    Set mobjCmd = Nothing
    
    mobjConn.Close
    Set mobjConn = Nothing

End Sub
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2174986
Latest Articles