AOA,

I m using vb6 with Access 2010 (DAO recordset) and Crystal Reports 9.22 I have developed a projet in vb6 it works fine at desing time but when i Install it (i mean after Package and deployment) and run the projet everything works fine but when i run reports it says:
Logon Failed:
DAO Error Code: 0xbe4
Source :DAO.Workspace
Discription : "D:....\MyData.MDB" is not a valid path. Make sure the path name is spelled correctly and that
you are connected to the server on which the file resides.

How can i change the datasource location in crystal reports at runtime.
Can any body give me the solution pls.

Dim m_report As CRAXDDRT.Report
Dim m_app As New CRAXDDRT.Application
On Error GoTo Hell
Set m_report = m_app.OpenReport(App.Path & "\Reports\rpt_Graduates.rpt")
'discard the save on the report
m_report.DiscardSavedData
'use app.path to retrieve the database of your report.'
m_report.Database.Tables(1).Location = App.Path & "\Database\GraduatesData.mdb"
m_report.Database.Tables(1).SetLogOnInfo "GraduatesData.mdb", "Table name of your Dbase", "Admin", "urDBpassword if any otherwise live it blank"
'i call something in my code to retrive the printer settings and my formula so ignore those two call below'
Call GetPrinterSettings
Call FormulaCode
'proceed here'
m_report.RecordSelectionFormula = "{Grad_List.Yr_Grad} =('" & frmViewGE.cboGrad.Text & "')"
rpt_Viewer.CRViewer1.ReportSource = m_report
rpt_Viewer.CRViewer1.ViewReport
rpt_Viewer.MousePointer = 0
Exit Sub
Hell:
MsgBox Err.Description & vbCrLf & "Please contact your system provider!", vbExclamation, "Error"
End Sub

Dear jhaiyz, Thanks for ur post, I tried your code but the problem is remain there.
Thing is that my uncompiled project(codes) i.e desing mode resides on a different Drive say "D:...." and i install the project on an other driver say "C:..\" and I have used App.Path through out the project. Now after installation every thing works fine but when i run reports, it Looks for the desing mod location i.e for "D:....". same problem occurs when i install it on different machine.

I encountered that error also when i was new in crystal report and i forgot to say that i am using 8.5 version of crystal. That code works fine for me even moving my project into another drive and even installing it on another machine without vb6 and crystal report installed. When compilling project, try to include all runtime files for crystal...Now try to design a report wothout using the DAO provider. Try to use the find database file when looking for ur database then try my code above. if error still persist, please post ur code and lets try to check it out...

AOA, Dear Mr. jhaiyz, thank u very much for suggestion and codes, after making a bit changes in the code sent by u, the problem is fixed. I just amended your code line No. 9.

m_report.Database.Tables(1).SetLogOnInfo "GraduatesData.mdb", "Table name of your Dbase", "Admin", "urDBpassword if any otherwise live it blank"

to as

m_report.Database.Tables(1).SetLogOnInfo "", App.Path & "Database\GraduatesData.mdb", "", ""

Thanks for ur help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.