paulette33
Technical User
This is the first time that I've used the Data Reports in VB. I have an application that connects to a Access 2000 database. I've create reports in VB using the data report. Is there a way to dynamically connect to the database? For instance, when I go from my laptop to my desktop, I have to reset the connection source for the database. I've tried calling the code that I have in one of the classes that opens the database connection, but it doesn't work. I've listed that code below. Any suggestions?
Thanks in advance for your help!
Public Function OpenConnection(ByVal pstrDatabaseName As String) As Boolean
On Error GoTo ConnectionError
Set cnnADO = New ADODB.Connection
With cnnADO
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Mode=ReadWrite;Persist Security Info=False;" & _
"Data Source=" & App.Path & "\" & pstrDatabaseName
.CursorLocation = adUseClient
.Open
If cnnADO.State = adStateOpen Then
OpenConnection = True
Else
OpenConnection = False
End If
End With
ConnectionExit:
Exit Function
ConnectionError:
OpenConnection = False
strMsg = "Unable to connect to " & pstrDatabaseName & " Access database. " & _
CStr(Err.Number) & " " & Err.Description
MsgBox strMsg, vbCritical, "Access ADO test application"
Resume ConnectionExit
End Function
Thanks in advance for your help!
Code:
On Error GoTo ConnectionError
Set cnnADO = New ADODB.Connection
With cnnADO
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Mode=ReadWrite;Persist Security Info=False;" & _
"Data Source=" & App.Path & "\" & pstrDatabaseName
.CursorLocation = adUseClient
.Open
If cnnADO.State = adStateOpen Then
OpenConnection = True
Else
OpenConnection = False
End If
End With
ConnectionExit:
Exit Function
ConnectionError:
OpenConnection = False
strMsg = "Unable to connect to " & pstrDatabaseName & " Access database. " & _
CStr(Err.Number) & " " & Err.Description
MsgBox strMsg, vbCritical, "Access ADO test application"
Resume ConnectionExit
End Function
Code: