Solved

Passing data in listbox into Crystal Report

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

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now