Help with ADO connection string - Access 2007

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
 
D

Douglas J. Steele

You mean

strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=f:\data\mydb.accdb;"

?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top