C
Corta
Hello, I need help getting the ADO connection string syntax right for
my Access 2007 Db application. Below is my code. My backend
database
file is located at "f:\data\mydb.accdb". I basically need to replace
the "Data Source" argument with the hard path to my database in the
strConnection setup.
Thanks for your help.
Corta
Sub RecordCount()
Dim cnCh5 As ADODB.Connection
Dim rsContacts As ADODB.Recordset
Dim strConnection As String
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & CurrentProject.Path &
"\Ch5CodeExamples.accdb;"
'create a new connection instance and open it using the connection
string
Set cnCh5 = New ADODB.Connection
cnCh5.Open strConnection
'create a new instance of a recordset
Set rsContacts = New ADODB.Recordset
'set various properties of the recordset
With rsContacts
.CursorType = adOpenStatic
'open the recordset based on tblContacts table using the existing
connection
.Open "tblContacts", cnCh5
End With
'print the number of records to the Immediate Window
Debug.Print "The total number of records is: " &
rsContacts.RecordCount
'close the database connection
cnCh5.Close
'set the recordset and connection to nothing
Set rsContacts = Nothing
Set cnCh5 = Nothing
End Sub
my Access 2007 Db application. Below is my code. My backend
database
file is located at "f:\data\mydb.accdb". I basically need to replace
the "Data Source" argument with the hard path to my database in the
strConnection setup.
Thanks for your help.
Corta
Sub RecordCount()
Dim cnCh5 As ADODB.Connection
Dim rsContacts As ADODB.Recordset
Dim strConnection As String
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & CurrentProject.Path &
"\Ch5CodeExamples.accdb;"
'create a new connection instance and open it using the connection
string
Set cnCh5 = New ADODB.Connection
cnCh5.Open strConnection
'create a new instance of a recordset
Set rsContacts = New ADODB.Recordset
'set various properties of the recordset
With rsContacts
.CursorType = adOpenStatic
'open the recordset based on tblContacts table using the existing
connection
.Open "tblContacts", cnCh5
End With
'print the number of records to the Immediate Window
Debug.Print "The total number of records is: " &
rsContacts.RecordCount
'close the database connection
cnCh5.Close
'set the recordset and connection to nothing
Set rsContacts = Nothing
Set cnCh5 = Nothing
End Sub