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.

Dani AI

Generated

The 0xBE4 you see is DAO error 3044, which simply means the report is still pointing at the design-time path (your D: drive). So even though your EXE uses App.Path, Crystal is trying to use the saved path inside the .rpt. The fix is to repoint every table at runtime (and every subreport’s tables) and not rely on what was saved at design time. Also, if you are only running reports, reference CRAXDRT (runtime) rather than CRAXDDRT. (github.com)

Building on and ’s notes, the pattern below avoids hardcoded drives, handles subreports, and keeps the existing table names. Notice the safe path join so a missing backslash does not cause 3044 again.

' VB6 + Crystal RDC (CR 9)
Private Function BuildPath(base As String, rel As String) As String
  If Right$(base, 1) = "\" Then BuildPath = base & rel Else BuildPath = base & "\" & rel
End Function

Private Sub RepointReport(rpt As CRAXDRT.Report, mdb As String)
  Dim t As CRAXDRT.DatabaseTable
  For Each t In rpt.Database.Tables
    t.SetLogOnInfo "", mdb, "", ""           'Access: server="", database=full .mdb path
    t.SetTableLocation mdb, t.Name, ""       'Keep the original table name
  Next

  Dim s As CRAXDRT.Section, ro As Object, sr As CRAXDRT.Report
  For Each s In rpt.Sections
    For Each ro In s.ReportObjects
      If ro.Kind = crSubreportObject Then
        Set sr = ro.OpenSubreport
        RepointReport sr, mdb                 'Repoint subreport tables too
      End If
    Next
  Next
End Sub

Tips that often get missed:

  • Call DiscardSavedData before viewing so you do not see stale, design-time data.
  • If you redesign reports in the future, consider using an OLE DB (Jet 4.0) connection to the .mdb rather than DAO; it is less brittle for path changes and avoids DAO-specific errors. Your Data Source is simply the full .mdb path. (learn.microsoft.com)

Recommended Answers

All 4 Replies

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.