I'm using ADO to make a SQL query in VBA.
I don't want to have to specify the path to the database. The database I'm querying will always be the same file in which the code is found, and its location will change. But I'm not sure how to set the path to "this file."
Here is a snippet from my code to give you a general idea:
I don't want to have to specify the path to the database. The database I'm querying will always be the same file in which the code is found, and its location will change. But I'm not sure how to set the path to "this file."
Here is a snippet from my code to give you a general idea:
Code:
Function AnythingThere()
Dim strConnection As String
Dim cnConnection As ADODB.Connection
Dim cmdCommand As ADODB.Command
Dim rsRecordset As ADODB.Recordset
Set cnConnection = New ADODB.Connection
Set cmdCommand = New ADODB.Command
Set rsRecordset = New ADODB.Recordset
' Right here is the problem. I don't want to have to specify a path and filename.
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & CurrentProject.Path & "\MyDatabaseName.accdb;"
cnConnection.Open strConnection
rsRecordset.Open "SELECT * FROM tblSupplier", cnConnection