Results 1 to 7 of 7

Thread: VB6 with CR9

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    VB6 with CR9

    Hi
    I have a listbox that contains up to 20 items.I want to write each item into a crystal report 9 report
    The code I will be using is:

    VB Code:
    1. For i=0 to lstitems.listcount-1
    2. slist=lstitems.list(i)
    3. ...'here I want to add the slist into CR9
    4. ...'here's the rest of my code
    5. Next i

    Can anyone help me because i'm new to CR9.

    thanks in advance

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: VB6 with CR9

    You have a couple options.

    1) you can call the report using a "select- like" statement:

    VB Code:
    1. Report.RecordSelectionFormula = "{DestroyAuth.SEQ} = " & CLng(lblSequence.Caption)

    2) you add a parameter to the report and pass the parameter value:
    VB Code:
    1. Report.ParameterFields.Item(1).AddCurrentValue cust

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

    Re: VB6 with CR9

    You can also use an ADO recordset for the DataSource of the report and in preparing it you can use your list items to build a sql select statement as your recordset source.
    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Re: VB6 with CR9

    I tried

    VB Code:
    1. For i=0 to list1.list(i)
    2. Report.ParameterFields.Item(1).AddCurrentValue list1.list(i)
    3. Next i

    It returned to me:

    "Script out of range"

    What's wrong?

    Thanks

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

    Re: VB6 with CR9

    You need to .Add a parameter first before you can reference it.
    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Re: VB6 with CR9

    RobDog888,I used ur example of VB6/Crystal Report present in your signature in order to display a recordset,what i want also is to display the content of a listbox in the report footer,so I added a parameter to the report and place it in the page footer(When creating the parameter i entered its name and type and I checked discrete value).When I execute the following code:

    VB Code:
    1. Rs.Open str2, cnn, adOpenStatic, adLockOptimistic
    2. Set oApp = New CRAXDRT.Application
    3.     Set oReport = oApp.OpenReport(App.Path & "\Report2.rpt", 1)
    4.     For l = 0 To List1.List(l)
    5.     oReport.ParameterFields.Item(1).AddCurrentValue List1.List(l)
    6.     Next l
    7.     oReport.Database.SetDataSource Rs, 3, 1
    8.     crvMyCRViewer.ReportSource = oReport
    9.     crvMyCRViewer.ViewReport
    10.     crvMyCRViewer.Refresh
    11. Rs.Close
    12.  
    13. End Sub

    It returned to me "Type mismatch" and it highlighted the For loop.
    So I removed the For loop and I replaced it by:
    oReport.ParameterFields.Item(1).AddCurrentValue List1.List(0)

    the code prompted me to enter a discrete value of the parameter,I entered a string and It was added to the report's footer.

    How should I create the parameter?discrete value,range value or ...

    and what's wrong with the for loop?

    Thanks in advance

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

    Re: VB6 with CR9

    Did you make it a Text/String type in CR? If its a footer then your only placing in one parameter so why the loop? You should always .Clear before you .Add the parameter value.
    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