Solved

Passing data in listbox into Crystal Report

Posted on 2004-07-30
10
1,207 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
  • 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 100

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
Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

 

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 100

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 50 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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