[RESOLVED] VB 6 And Crystal Report 8.5-VBForums
Results 1 to 11 of 11

Thread: [RESOLVED] VB 6 And Crystal Report 8.5

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2014
    Posts
    53

    Resolved [RESOLVED] VB 6 And Crystal Report 8.5

    Hello All,

    I'm using this codes to connect CR

    Code:
    Private sub Command2.Click()
    
    Dim crxTable As CRAXDRT.DatabaseTable
    Dim mReport As CRAXDRT.Report
    For Each crxTable In mReport.Database.Tables
    crxTable.SetLogOnInfo "ODBCDATA", "Data.mdb", "admin", ""
    DoEvents
    Next
    
    End sub
    But i always met with the error "OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET" (Highlighted line)

    How to face with the error and any other options to connect database with ODBC

    ( I Already connected CR 8.5 with access with ole db. I installed my program on another computer. But crystal report
    did't search access file in application installed folder.. so i searched in google and crystal report forums everyone said
    to connect it with odbc.. So i do it.. But the error was blocking me..)

    How can i do this..
    Please Help.

    Thanks to spend your time with my question..
    Thank You

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,191

    Re: VB 6 And Crystal Report 8.5

    Thread moved from the 'VB6 and Earlier' forum to the 'Reporting' forum

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2014
    Posts
    53

    Re: VB 6 And Crystal Report 8.5

    ohh...sorry..thank you

  4. #4
    Frenzied Member
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    2,044

    Re: VB 6 And Crystal Report 8.5

    Never used cr in VB6, only vb .Net. But it seem like you would to change this,
    Code:
    Dim mReport As CRAXDRT.Report
    to
    Code:
    Dim mReport As NEW CRAXDRT.Report
    Also, you haven't loaded a report to "mReport", so the "For Loop" seems pointless.

  5. #5
    Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    53

    Re: VB 6 And Crystal Report 8.5

    Quote Originally Posted by wes4dbt View Post
    Code:
    Dim mReport As NEW CRAXDRT.Report
    Do you mean this?

    Code:
    Set mReport = NEW CRAXDRT.Report
    Computer Enterprise Masoud Keshavarz
    For more information contact masoudk1990@yahoo.com

  6. #6
    Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    53

    Re: VB 6 And Crystal Report 8.5

    From here http://www.mahipalreddy.com/cr/article52645.htm

    Something like this should work:

    Code:
    'Add a command button and a Crystal Report Viewer Control to you form
    'Reference Crystal Reports 8/8.5/9/10 ActiveX Designer Run time Library
    'Paste the following code into the form code window
    'Change the path "C:\crtests\Report1.rpt" to suit yours
    
    Private Sub Command1_Click()
        Dim CrxApp As CRAXDRT.Application
        Dim CrxRep As CRAXDRT.Report
        Dim crxDatabase As CRAXDRT.Database
        Dim crxDatabaseTables As CRAXDRT.DatabaseTables
        Dim crxDatabaseTable As CRAXDRT.DatabaseTable
    
        Set CrxApp = New CRAXDRT.Application
        Set CrxRep = CrxApp.OpenReport("H:\test\crtests\Report1.rpt")
        
        'Set your Database object to the Report object's Database object
        Set crxDatabase = CrxRep.Database
        
        'Set your DatabaseTables object to the Database object's Tables object
        Set crxDatabaseTables = crxDatabase.Tables
        
        'Loop through each DatabaseTable object in the DatabaseTables collection and then set the location
        'of the database file for each table
        
        For Each crxDatabaseTable In crxDatabaseTables
            'If you are using physical path of the access database file (Native connection to PC database)
            crxDatabaseTable.Location = App.Path & "\xtremelite.mdb"
    
            'Use next line, if you are using Native connection to SQL database
            'crxDatabaseTable.SetLogOnInfo "servername", "databasename", "userid", "password"
    
            'Use next line, if you are using ODBC connection to a PC or SQL database
            'crxDatabaseTable.SetLogOnInfo "ODBC_DSN", "databasename", "userid", "password"
        Next crxDatabaseTable
        
        
        CRViewer91.ReportSource = CrxRep
        CRViewer91.ViewReport
        
        Set crxDatabase = Nothing
        Set crxDatabaseTable = Nothing
        Set crxDatabaseTables = Nothing
        Set crxReport = Nothing
        Set crxApplication = Nothing
    
    End Sub
    Computer Enterprise Masoud Keshavarz
    For more information contact masoudk1990@yahoo.com

  7. #7
    Frenzied Member
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    2,044

    Re: VB 6 And Crystal Report 8.5

    Do you mean this?

    Code:
    Set mReport = NEW CRAXDRT.Report
    No, I use the method in my post to create many objects. But, I've never tried it with CR. Have you?

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2014
    Posts
    53

    Re: VB 6 And Crystal Report 8.5

    Thanks guys,

    masoudk1990 Thanks.. It works..But i need to use the crystal report control. not crystal report viewer..

    wes4dbt thanks.. but i got another error in the same line ... the error was "Method 'Database' of object 'IReport' Failed."

    How can i face the error.

    Thank you..

  9. #9
    Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    53

    Re: VB 6 And Crystal Report 8.5

    No, I use the method in my post to create many objects. But, I've never tried it with CR. Have you?
    sorry wes4dbt it was my fault.

    kamalkumar2023, as wes4dbt said earlier you havent set "mReport".
    You must have something like this in your code before foreach loop:

    Code:
    Set mReport = crxApplication.OpenReport(App.path & "\MyReport.rpt")
    Also I can not find this declaration in your click event:

    Code:
    crxApplication As New CRAXDRT.Application
    Is it your full code? Please provide us your full and updated code.
    Computer Enterprise Masoud Keshavarz
    For more information contact masoudk1990@yahoo.com

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2014
    Posts
    53

    Re: VB 6 And Crystal Report 8.5

    Thanks Mr.masoudk

    My Question was HOW TO CONNECT ACCESS WITH CRYSTAL REPORT via ODBC with VB 6.

    here is my full code

    Code:
    Private Sub Command4_Click()
    Dim crxTable As CRAXDRT.DatabaseTable
    Dim mReport As New CRAXDRT.report
    Dim crxApplication As New CRAXDRT.Application
    Set mReport = crxApplication.openreport("F:\Kamal\New VB Collections\GK LAB\Report\Checking.rpt")
    For Each crxTable In mReport.Database.Tables
    crxTable.SetLogOnInfo "GK DATA", "Data.mdb", "admin", ""
    DoEvents
    Next
    With CR
    .Destination = crptToWindow
    .WindowState = crptMaximized
    .Action = 1
    End With
    
    End Sub
    with any changes does this code work for my question ???? or any other ?????

    Thank you,

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2014
    Posts
    53

    Re: VB 6 And Crystal Report 8.5

    Thanks guys, I GOT IT

    Code:
    Private Sub Command4_Click()
    
    With CR
    .ReportFileName = App.Path & "\Report\Checking.rpt"
    .ReplaceSelectionFormula "{R_Patient.regno} =" & Text1.Text & ""
    .Connect = "Dsn=GK DATA;Uid=sa;pwd=admin;dsq=database"
    .Destination = crptToWindow
    .WindowState = crptMaximized
    .Action = 1
    End With
    
    End Sub
    It works..

    Thanks Again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.