Solved

Passing data in listbox into Crystal Report

Posted on 2004-07-30
10
1,176 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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