Results 1 to 7 of 7

Thread: code help (RobDog888)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    code help (RobDog888)

    I copied your preview Crystal Report code and I can't get it to work. Here is what I have...can you please tell me what I'm missing????

    <VB Code>

    Private Sub Command1_Click()

    Dim oApp As CRAXDRT.Application
    Dim oReport As CRAXDRT.report
    Dim oRs As ADODB.Recordset
    Dim sSQL As String
    Dim db As Database

    Set db = CurrentDb

    sSQL = "SELECT * FROM Posted_Trans_Weekly"
    Set oRs = New ADODB.Recordset
    Set oRs = oCnn.Execute(sSQL)
    Set oApp = New CRAXDRT.Application
    Set oReport = oApp.OpenReport("c\test.rpt", 1)
    oReport.Database.SetDataSource oRs, 3, 1
    crvMyCRViewer.ReportSource = oReport
    crvMyCRViewer.ViewReport

    End Sub
    <\VB code>

    I'm getting an error message on the line oCnn.Execute (sSQL). Error message is "Compile error. Variable not defined."
    Last edited by kchisley; Jan 23rd, 2006 at 10:36 AM.

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

    Re: code help (RobDog888)

    The object oCnn has not be declared (or initialised!). You should generally either use DAO (your db variable) or ADO (your oRs variable), but not both.

    For an example of setting up an ADO connection, see the ADO Tutorial link in my siganture.


    Oh, and the VBCode tags on this forum need to be like this:
    [vbcode]code here[/vbcode]

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Exclamation Re: code help (RobDog888)

    OK. thanks for your help. But, now I'm getting an error message in the crvMyCRViewer line of the code. It says variable not defined. How do I declare this variable so that I can use the viewer?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: code help (RobDog888)

    That would be a control, which needs to be added to your form (presumably called "CRViewer" in the toolbox, which you should call "crvMyCRViewer" when you put it on your form).

    If the control isn't in your toolbox, you will need to go to "Project"->"Components", and select it from the list.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Question Re: code help (RobDog888)

    I'm sorry to sound so stupid, but the form you're referring to is an Access form? As of right now, I'm not using a form of any kind. I'm simply trying to build the code to preview the report. Can that be done?
    Last edited by kchisley; Jan 23rd, 2006 at 11:20 AM.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: code help (RobDog888)

    Yes, that is the kind of form I meant. I don't know if you can preview a report without the control (I've never tried), so you may have to add a hidden form with the control on it (in which case you could use formname.crvMyCRViewer).

    This thread shows how to print without the control (in your case, oReport.Printout False) but not how to preview it. There may be some kind of preview option - just see what Methods the oReport object provides.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: code help (RobDog888)

    AFAIK, since I have only used CR 8.5 Developer, you ccan not preview a report without the CR Viewer control as that is what it was mean to be used for.

    You could Export the report to a pdf or something and then open it via code but then the report has all its data in the file. so if a refresh or change is needed you will need to re-Export it and open it again. Bot too professional looking but it doesnt use the Viewer control that way.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width