Solved

Passing data in listbox into Crystal Report

Posted on 2004-07-30
10
1,146 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 42

Accepted Solution

by:
frodoman earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
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 …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

16 Experts available now in Live!

Get 1:1 Help Now