Solved

How to print report by capture user inputs in Visual Basic?

Posted on 2001-07-06
18
434 Views
Last Modified: 2007-12-19
How do i print out a report by capture user inputs in visual basic? Can anyone show me a code? My crystal report's version is 4.5. Thanks.
0
Comment
Question by:beingy
  • 10
  • 7
18 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6260222
Never used version 4.5.

Current versions have at least two primary ways of passing user entered data to a report to control what appears.  First, you can use parameter fields and have Crystal Reports prompt the user when the report runs.  Second, you can use Visual Basic or Delphi to put a front end program in place that uses forms to prompt the user and then pass that data to the report.

Check the help files that came with your version for specifics - I could give you version 8 syntax, but I have no idea how much it has changed over the years.
0
 

Author Comment

by:beingy
ID: 6263848
To drryan3:

can you show me some simple coding of how do use the second method that you mentioned. My CR version is not come with parameter fetures.Thanks.
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6265312
Beingy

If your version (4.5) doesn't support parameters, it is unlikely that it will support passing parameters from Visual Basic forms.
0
 

Author Comment

by:beingy
ID: 6265636
drryan3

as i know, i can try to use formula, right? i set a formule in CR, then write a code in vb to capture user input then pass it into the formula. this only my idea, i not yet try it out. any idea?
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6265703
You could try

<controlname>.ReplaceSelectionFormula("new selection formula")
<controlname>.action = 1
0
 

Author Comment

by:beingy
ID: 6267673
drryan3

thanks for your help. i'll try it later. so, one more question to ask. do you know how do refresh the report data by writing the code in vb. can you show me?
thanks again.
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6267692
Generally, you need to make sure that you have unchecked the option in CRW Designer to save data with your report and then save the report again.  That's all I generally do.

If you can't do that, see if you have the DiscardSavedData property and if so, set it to 1  (true).  This is called PEDiscardSavedData in the CR Report Engine.

Good Luck
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6267694
On a related note, if you are planning to do any serious work with VB and CRW, consider upgrading to a newer version that 4.5.  There are lots of new pieces in the object models, and the integration is better/smoother.
0
 

Author Comment

by:beingy
ID: 6272240
drryan3:

my one is vb6.0 (98 2nd enterprise edition). are this version compatible with the latest crw7/8.0?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6301032
Sorry for the delay in answering - vacation.

Yes.  VB 6.0 on 98 SE is compatible with the latest versions of CRW - 7 and 8.0/8.5.
0
 

Author Comment

by:beingy
ID: 6301454
drryan3:

Can you tell me more about how do use selection formula? i try to use it to capture user inputs but cannot.

I heard from my friend, the crystal report for VB and seagate crystal report are two different versions, isn't?

Are the preview button cann't be used if want to print the latest data from the database?

Thanks for help.




0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6302902
There was a version of Crystal Reports that MS included at one time with VB.  That is different than the retail version of CRW and is probably not upgradeable to the latest version.

If your question about selection formulas is for version 4.5, I don't have info on the API for that version.  If for version 7 or later, let me know.

The report preview feature of CRW can be used if you want to show the latest version of the data in the database.  You must make sure that you have saved the report (.RPT) file without saved data.
0
 

Author Comment

by:beingy
ID: 6307011
Once i created the report, i go to file-option then uncheck the save data with closed report. And then i preview the report and save as *.rpt. After that, i try to add the new records, and i call up the report in vb, but the report doesn't show the latest one.but the report was updated if i open it at crystal report.
what is the problem? am i correct? please help.

That is the code i wrote in vb. any errors?
controlname.reportfilename = "c:\abc.rpt"
controlname.destination = crpttoprinter
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6307317
You might try adding

controlname.discardsaveddata

as well.
0
 

Author Comment

by:beingy
ID: 6315675
I arealdy upgrade my version to 8.0, so can you show me how to do the selection formula in turn to print report based on user input in vb? thank you very much.
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6315755
Create a form containing the fields you want to match on.  Let's say you have two:  txtF1 and txtF2

Make sure you add a reference to your project for Crystal Viewer.

Put a button on the form labeledl PRINT or use the CRW Wizard and add the following code to that button:

   CR1.ReportFileName = "C:\CRYSTAL\MYREPORTNAME.RPT"
   CR1.Destination = crptToWindow  ' for print preview
   CR1.DiscardSavedData = True
 
   ' HERE IS THE BIT YOU ARE INTERESTED IN
   CR1.ReplaceSelectionFormula _
       "{MYTABLE.FIELD1} = '" & txtF1.text & "' AND " & _
       "{MYTABLE.FIELD2} = '" & txtF2.text & "'"

   CR1.ProgressDialog = True
   CR1.WindowShowCancelBtn = False
   CR1.WindowShowCloseBtn = True
   CR1.WindowBorderStyle = crptSizable
   CR1.WindowShowNavigationCtls = True
   CR1.WindowShowPrintBtn = True
   CR1.WindowShowPrintSetupBtn = True
   CR1.WindowShowSearchBtn = True
   CR1.WindowShowZoomCtl = True
   CR1.PrintReport
   If CR1.LastErrorNumber <> 0 Then
     MsgBox "Crystal Reports Error Number " & CR1.LastErrorNumber & vbCrLf & CR1.LastErrorString, vbExclamation
+ vbOKOnly, "Crystal Reports Error"
   End If
0
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 50 total points
ID: 6324773
beingy

I'll assume unless you comment otherwise that that code was what you needed.

DRRYAN3
0
 

Expert Comment

by:ComTech
ID: 6494468
I agree with DRRYAN3 and will accept the answer.

Thank you,
ComTech
Community Support Moderator

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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