Um, yes. Didn't I put them at the top of the code in Dim statements?
objConnection is an ADODB.Connection object
sDatabasePath is a string which is the location of the database.
sConnection is also a string which is used to create the objConnection.
Let me send you some code of one of my routines as I am obviously making a
mess here.
I use this code to create the objConnection object. One passes in an
objConnection object which is created elsewhere and also the path to the
database.
I do it this way because I want to make sure that I am not trying to use
an already opened database connection.
For example:
Dim sDatabase As String
Dim conDisplayDB As ADODB.Connection
sDatabase = recDatabase.sDisplayResultsDatabase
If CreateDatabaseConnection(conDisplayDB, sDatabase) Then
End If
Private Function CreateDatabaseConnection( _
ByRef objConnection As ADODB.Connection, _
ByVal sDatabasePath As String) As Boolean
Dim sConnection As String
Dim bRetVal As Boolean
On Error GoTo Error_OpenDatabaseConnection
bRetVal = False
If Not objConnection Is Nothing Then
' Connection object is still valid
bRetVal = True
GoTo Exit_OpenDatabaseConnection
End If
Set objConnection = New ADODB.Connection
sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sDatabasePath
If Len(sConnection) > 0 Then
' Remove the time out
objConnection.ConnectionTimeout = 0
objConnection.ConnectionString = sConnection
objConnection.open
bRetVal = True
Else
MsgBox "Unable to open database connection.", _
vbOKOnly + vbExclamation, "Error"
End If
Exit_OpenDatabaseConnection:
On Error Resume Next
CreateDatabaseConnection = bRetVal
Exit Function
Error_OpenDatabaseConnection:
bRetVal = False
MsgBox Str$(Err.Number) & ": " + Err.Description, _
vbOKOnly + vbExclamation, "Database open error"
Resume Exit_OpenDatabaseConnection
End Function
What happens here is that in the calling code I want to make sure that the
connection is opened. If it is not already open (it shouldn't happen, but
I like to make sure) then it will create a database connection pointing to
the location of the database held within the sDatabase string.
This string holds the location of the database. In my code you will see
that I have a record structure, as it happens, this is populated at the
start time from the registry with the database locations.
I am drifting off-topic here, but the idea is that you can see that I have
a connection object and a variable containing the database. I throw these
into the OpenDatabaseConnection() function and then I end up with a fully
working conDisplayDB connection object.
Then, as in previous mails, I work on that.
Have I confused you even more? If so, I will start again.
Malc
www.dragondrop.com