Solved

VB6 and Crystal Reports 8

Posted on 2000-04-02
15
164 Views
Last Modified: 2010-05-02
I have placed my code at the following web site http://thedoves.net

I want to be able to use the variables from the FmReports (DataCombo1, DTPicker1, and DTPicker2) to pass to the CRViewer on FmEmpEmployees.

Can some one show me how this is done?  I want to use the RDC, instead of the OCX.  Thanks In Advance!
0
Comment
Question by:tdove
  • 8
  • 7
15 Comments
 
LVL 2

Expert Comment

by:isstorr
ID: 2680870
hi tdove,

This derived from the CR8 VB help -

First prevent the ugly variable entry boxes from appearing -

CrystalReport1.EnableParameterPrompting = False

Now to pass in the vars -

private sub PassParams()
Dim crpParamDefs As CRAXDRT.ParameterFieldDefinitions
Dim crpParamDef As CRAXDRT.ParameterFieldDefinition

Set crpParamDefs = CrystalReport1.ParameterFields
   For Each crpParamDef In crpParamDefs
      With crpParamDef
         .ClearCurrentValueAndRange
         Select Case .ParameterFieldName
            Case "DTPicker1.Value"
            .SetCurrentValue DTPicker1.Value
            Case "DTPicker2.Value"
            .SetCurrentValue DTPicker2.Value
            Case "Datacombo1.Text"
            .SetCurrentValue  DataCombo1.Text
         End Select
      End With
   Next
End Sub

Hope this helps!

Si
0
 

Author Comment

by:tdove
ID: 2682272
Can you give me a little more help than that?  I tried it and it isn't working.

I am new to VB and Crystal Reports, I sorta got volunteered to make this thing work....

Thanks In Advance!

Todd
0
 
LVL 2

Expert Comment

by:isstorr
ID: 2683083
hi Todd,
Could you say why its not working?
Sorry I didn't explain what I was doing. You need to place the EnableParameterPrompting
command in your FmReports Form_Load event, and the PassParams sub in FmReports as well.

'PassParams creates a structure to hold the reports Parameter Fields -
Dim crpParamDefs As CRAXDRT.ParameterFieldDefinitions

'and an individual parameter variable -

Dim crpParamDef As CRAXDRT.ParameterFieldDefinition

' set the parameters to the report's parameters
Set crpParamDefs = CrystalReport1.ParameterFields

' now go through each parameter in turn and set its values from your 3 controls
   For Each crpParamDef In crpParamDefs
      With crpParamDef

' clear any old parameter values
         .ClearCurrentValueAndRange


         Select Case .ParameterFieldName
            Case "DTPicker1.Value"
            .SetCurrentValue DTPicker1.Value
            Case "DTPicker2.Value"
            .SetCurrentValue DTPicker2.Value
            Case "DataCombo1.Text"
            .SetCurrentValue DataCombo1.Text
         End Select
      End With
   Next
End Sub

0
 
LVL 2

Expert Comment

by:isstorr
ID: 2683093
note the Case statement strings are case sensitive (they have to exactly match the names you gave the parameters in the report) and I had incorrectly typed 'Datacombo1' instead of 'DataCombo1' in my 1st post :o)
0
 

Author Comment

by:tdove
ID: 2683694
Hi-

The problems I am having are..

The Select box is still coming up from the Crystal Reports when displaying the Report and the Select criteria isn't working.

I tried putting the ParameterPrompting on the FmEmpEmployees form thinking that would help since that is where the CRViewer is, but it still didn't help.

Then I got to thinking how is the PassParameters() working since it is a Private Sub on FmReports?  How is the variables passed to the Crystal Reports?

Thanks!

0
 

Author Comment

by:tdove
ID: 2683861
Ok...I have figured out why the selection box was coming up! (Yeah!)
I changed CrystalReport1.EnableParameterPrompting = False to Report.EnableParameterPrompting=False because I had DIM CrystalReport1 to Report.  So that is taking care of.

But the parameters are not being passed from FmReports to the CRViewer1 on FmEmpEmployees?
0
 
LVL 2

Expert Comment

by:isstorr
ID: 2683987
hmm sounds strange as it works for me..
I have developed a similar filtering system for my reports as it happens, and the routine I used I included above, modified to use your controls and fields.

the EnableParameterPrompting only needs to be called once when the app starts, so you can put it in your viewer form's form_load event if you want (actually this is what I did in my app)

The SetCurrentValue method sets the report parameter's value & PassParams is supposed to be in FmReports, so it can stay private as it only references the CrystalReport1 and the 3 data entry controls on the form.

It is also useful to have a way of clearing the selections by selecting 'all' as well - I just use a checkbox. If you have nothing selected in your dropdown list, then an empty string will get passed into the report parameter, which will result in nothing being selected, not what you would possibly expect.

Also setting a run-time connection (as in your command3_click procedure) will have no effect on the report (hence the need for the report parameters) which is a shame as the whole thing would be a lot easier just using SQL to set your record filtering :o)
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 2

Expert Comment

by:isstorr
ID: 2684015
I think your problem then is your Report variable - you should reference the report directly in FmEmpEmployee's Form_Load :-

CRViewer1.ReportSource = CrystalReport1
CRViewer1.ViewReport

The PassParams as it stands will set the parameters for the 'CrystalReport1' itself, not a copy such as 'Report'.

(I also posted the previous comment prior to reading your latest :>)
0
 

Author Comment

by:tdove
ID: 2684219
It all Works!!! Thanks For All Your Help!

I have one last question.  Since FmReports will have a case statement for the radio buttons for all the different Crystal Reports,I am going to have a different PassParams() for each different Crystal Report?

If yes, we are talking about ten different reports, how bad will this impact the speed the Form.FmReports loads?

Thanks Again For ALL YOUR HELP!
0
 
LVL 2

Accepted Solution

by:
isstorr earned 600 total points
ID: 2684356
no probs :> ..can u credit me now :oþ

Re different reports - well I am in the same position as each different report requires different input for its filters. If you are going to use the same controls for all your reports in one form, then you could get around it by making sure your report parameter names are unique across your reports, and pass in the report as a parameter to PassParams - eg.

  ' generic report PassParams
  ' note rep declared as Object - it is   the report we wish to filter
  private sub PassParams(rep as Object)

and change the line
   Set crpParamDefs = repRoomList.ParameterFields

to
   Set crpParamDefs = rep.ParameterFields

Then create case statements for each report parameter in each report. I can't see that this will affect load times greatly.

If you have different data entry screens for each report, then you will need a different PassParams for each entry screen to reference the controls.

happy reporting!
Si
0
 

Author Comment

by:tdove
ID: 2684379
That did it!  Thanks Again for all your help!!
0
 

Author Comment

by:tdove
ID: 2684499
That did it!  Thanks Again for all your help!!
0
 
LVL 2

Expert Comment

by:isstorr
ID: 2684537
cool - glad 2b of help.
You've earnt me my first points as well :>
0
 

Author Comment

by:tdove
ID: 2684659
Quick Question:

I am trying to do case statements, but am unsure how to set up the case statements.  Do you think you can give me an example of how this is done?
0
 

Author Comment

by:tdove
ID: 2684661
..using the rep.ParameterFields.
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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

930 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

13 Experts available now in Live!

Get 1:1 Help Now