Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how create subreport with crystalReports in vb6 and access db=?
in my code i have error logon failed
please help me ,thanks

What I have tried:

VB
Private Sub lvButtons_H6_Click()

    Dim Rs As New ADODB.Recordset

    If Rs.State = 1 Then Rs.Close
 
  '   If Rs.State = 1 Then Rs.Close

    If StrSQL = "" Then

       Rs.Open "SELECT ID,GroupName,Fname,LName FROM tblMain ORDER BY ID ASC", Conn, adOpenStatic, adLockOptimistic

    Else
On Error Resume Next
        Rs.Open StrSQL, Conn, adOpenStatic, adLockOptimistic

    End If

    StrSQLPrint = Rs.Source
     Set Me.VS.DataSource = Rs
  PrintMember StrSQLPrint
End Sub

Private Sub PrintMember(StrSQL As String)
'On Error GoTo E_R



Dim Rs As New ADODB.Recordset
'Dim ObjApp As New CRAXDRT.Application
'Dim ObjRpt As New CRAXDRT.report
'Dim crDBTab As CRAXDRT.DatabaseTable

If Rs.State = 1 Then Rs.Close
'MsgBox StrSQL, vbCritical
Rs.Open StrSQL, Conn

     Dim CrxApp As CRAXDRT.Application
    Dim CrxRep As CRAXDRT.report
    Dim crxSubreport As CRAXDRT.report
    Dim crxSubreportObject As SubreportObject
    Dim crxDatabase As CRAXDRT.Database
    Dim crxDatabaseTables As CRAXDRT.DatabaseTables
    Dim crxDatabaseTable As CRAXDRT.DatabaseTable
    Dim crxSections As CRAXDRT.Sections
    Dim crxSection As CRAXDRT.Section
    Dim CRXReportObject As Object
    
    Set CrxApp = New CRAXDRT.Application
    Set CrxRep = CrxApp.OpenReport(App.Path & "\Reports\R.rpt")
CrxRep.Database.SetDataSource Rs

    Set crxSections = CrxRep.Sections
    
    For Each crxSection In crxSections
        For Each CRXReportObject In crxSection.ReportObjects
           If CRXReportObject.Kind = crSubreportObject Then
             Set crxSubreportObject = CRXReportObject
             Set crxSubreport = crxSubreportObject.OpenSubreport
             Set crxDatabase = crxSubreport.Database
             Set crxDatabaseTables = crxDatabase.Tables
             
             For Each crxDatabaseTable In crxDatabaseTables

    crxDatabaseTable.Location = App.Path & "\Database.mdb"


    crxDatabaseTable.SetLogOnInfo "Local", "Database.mdb", "Admin", "123456"
             Next
             
             Set crxSubreport = Nothing
           End If
        Next
    Next
    
    Frm_Preview.CR.ReportSource = CrxRep
    Frm_Preview.CR.ViewReport
        Frm_Preview.Show vbModeless, MainForm
        
    Set crxDatabase = Nothing
    Set crxDatabaseTable = Nothing
    Set crxDatabaseTables = Nothing
    Set crxSections = Nothing
    Set crxSection = Nothing
    Set crxSubreportObject = Nothing
    Set crxReport = Nothing
    Set crxApplication = Nothing
End sub
Posted
Updated 9-Apr-17 23:35pm
v2

1 solution

Apart from the fact you have already posted this question on the VB forums: vb6 crystal report- subreport - Visual Basic Discussion Boards[^], you state here
hoomi_ghost said:
in my code i have error logon failed
Which I'm guessing is produced by this line:
crxDatabaseTable.SetLogOnInfo "Local", "Database.mdb", "Admin", "123456"
It would imply that password you are using is incorrect. Incidentally, you should avoid using the Admin account for stuff like this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900