Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Data Report connection source

Status
Not open for further replies.

paulette33

Technical User
Mar 15, 2002
27
US
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!

Code:
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
Code:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top