Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing data in listbox into Crystal Report

Posted on 2004-07-30
10
Medium Priority
?
1,311 Views
Last Modified: 2011-09-20
Hi expert,

I have problem to pass all data (more than one) in a listbox so it could be printed in Crystal Report. I need this way to print any recordsets that we like to print. I add it fist at a listbox, then being passed to Crystal Report. I've tried such as it done with text object. But, Crystal Report doesn't recognise it.

Hopefully you could help me.

Thank you.
0
Comment
Question by:masagung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 11675948
masaqunq,

Crystal doesn't care where the values come from - whether a listbox, textbox, hard coded, etc - crystal accepts the incoming parameter w/out any idea of how it was created.  

If Crystal isn't recognizing the value this is most likely because there's an error in your code that passes the value.  Also if you're passing more than one value in, make sure that your Crystal parameter is setup to allow multiple values.

frodoman
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11676230
well if you can pass your code, maybe we can help. other than that your code must be wrong as frodoman said

Regards
Emre
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 11676843
You could do it by passing an ADO recordset to the report

http://support.businessobjects.com/communityCS/FilesAndUpdates/ADO_ConnectionMethods.zip.asp

mlmcc
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 

Author Comment

by:masagung
ID: 11682974
Well, this is my code to call Crystal report that is going to preview all data in listbox. I build the Crystal Report file that doesn't n based on any tables.
The last error message is "Invalid Table Number".

------------------------------------------------
Private Sub Command1_Click()
  Dim ipserver As Database
  Dim uid2, pwd2, ds2 As String
  Dim RESIP, pathname

'******************************
 'Make connection to SQL Server
'******************************
  Set ipserver = OpenDatabase(App.Path & "\serverIP.mdb", False, False, ";pwd=SecretS")
  Set RESIP = ipserver.OpenRecordset("ServerIPAd")
 
  Set db = New ADODB.Connection
  db.Provider = "SQLOLEDB"
  db.CursorLocation = adUseClient
  uid2 = RESIP!UserName
  pwd2 = RESIP!Password
  ds2 = RESIP!IPAddress
 
  db.ConnectionString = "uid=" & uid2 & ";pwd=" & pwd2 & ";data Source=" & ds2 & ";Initial Catalog=DALANG;"
 
'****************
'Call Crystal Report
****************

CrystalReport2.LogonInfo(0) = db.ConnectionString   '"uid=AGUNG;pwd=SHAFIRA;data Source=10.52.7.254;Initial Catalog=DALANG;"
pathname = App.Path & "\report\Work Order.rpt"
CrystalReport2.ReportFileName = pathname

CrystalReport2.Formulas(1) = "Text =" & "'" & List1.ListIndex & "'"
CrystalReport2.WindowState = crptMaximized
CrystalReport2.Action = True
End Sub

------------------------------

Thank you for helping.

Regards
+Agung
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 11685682
Are you saying the report isn't based on any database or table?  If so then there is probably no need to use the logon information.

mlmcc
0
 
LVL 42

Accepted Solution

by:
frodoman earned 200 total points
ID: 11687433
Try CrystalReport2.LogonInfo(1) = ...   instead of CrystalReport2.LogonInfo(0) = ...

That should clear your invalid table number message.  


I agree with mlmcc though that passing a ado recordset makes more sense and then you don't need to hit a database at all.

frodoman
0
 

Author Comment

by:masagung
ID: 11711336
Ok, It's already done fine. I could call Crystal Report.
But, how to show all data in list box instead of using my code below :

CrystalReport2.Formulas(1) = "Text =" & "'" & List1.ListIndex & "'"


Using that code, I just could show only one Index.

Thank you in advance
Regards
=Agung
0
 
LVL 42

Expert Comment

by:frodoman
ID: 11711498
Are you asking how to loop through a listbox?  If so then here's the code:

       For Each li In YourListBox.Items
            If li.Selected = True Then
                'Put your code here
            End If
        Next

This acts upon selected items - if you want to act on all items just remove the If...Then construct.

Your code could be, for example:

       For Each li In YourListBox.Items
           MyString = MyString & " " & li.ListIndex
       Next
       CrystalReport2.Formulas(1) = "Text = '" & MyString & "'"

I don't know if this example is relevant because I"m not really sure what you're going for here...  Hopefully it's helpfull though.

frodoman
0
 

Author Comment

by:masagung
ID: 11711640
Frodoman,

I've tried your code. But, compiled error at this line :
................
For Each li In List1.Items
...............

VB said," Argument not optional ", even I have changed List1.Items to List1.Itemsdata.
Actually I want to pass all data in listbox to a single formula name in Crystal Report. So it could be printed as clear text.
I'm sure it must using loop through a listbox. I haven't found a sample code to do it.

Regards
=Agung


0
 

Author Comment

by:masagung
ID: 11713598
Hi all, my problem's already done. I have found the best way to solve it.
Thank you very much

Regards
+Agung
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question