Access database connection

Sub connector database ()
 'The first step: we have to use ADO reference AD tools
 ' Step 2: Create a connection object
 '2-1: to take the name of the connection object, declare an object
 ' Dim conn As ADODB.Connection 'declare an object variable
' 2-2: create object variable, and assign
'Set conn = New ADODB.Connection' to create an object variable
'third step: to establish a database connection access database
' conn.Open "provider = microsoft.ace.oledb.12.0; data source = "& ThisWorkbook.Path &" \ student management .accdb "
'connecting the excel document
' conn.Open" provider = microsoft.ace.oledb.12.0; extended properties-excel 12.0; data source = "& ThisWorkbook.Path &" \ data .xlsx "
Dim conn of As New ADODB.Connection
With conn
  .Provider =" Microsoft.ACE.OLEDB.12.0 "
  .ConnectionString = ThisWorkbook.Path &" \ student management .accdb "
  .Open
End With
MsgBox "successful connection"
conn.Close
End Sub

Guess you like

Origin www.cnblogs.com/lyzifan/p/12519607.html