Solved

VB 5 and crystal report 8.5

Posted on 2004-04-18
7
887 Views
Last Modified: 2010-05-18
Hi all,

I've made a crystal report rpt file which churns out reports using an odbc connection with the db.
problem is, i have no idea how to let users enter variables (dates, to be exact) .

so i looked around and decided to use VB 5 (yes i know it's freakin old) as a front end to choose a date , and then pass the variables to the report .
I've added a crystal report control on the form and i can do a CrystalReport1.PrintReport .

how do i pass the variables to the rpt file, and how do i get them into the report's sql ? this is my first time using crystal report so i'm pretty lost.

also, i noticed that to refresh the data in the report , i need to key in the password again. how do i define the db connection and the password/username in vb ?
0
Comment
Question by:shenlong_wc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 125 total points
ID: 10865566
0
 

Author Comment

by:shenlong_wc
ID: 10936493
tried the links, 1 and 3 were unsuitable because i only have vb 5 and CR8.5

looking up the web, i now find that the code in vb is

crptReport.ParameterFields(0)="Broker;TR04;true"

but do i create that "Broker" variable and use it in the selection sql ?
0
 

Author Comment

by:shenlong_wc
ID: 10936500
i mean how do i create and use that variable in CR ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 100

Expert Comment

by:mlmcc
ID: 10967624
In CR
Open the report
Display the field popup or Click INSERT --> PARAMETER
Right click on PARAMETER
Select NEW
Name - Broker

It can now be used from VB

Did you try the methods.  I know they are listed as for CR9 but the RDC didn't change that much with CR9 so the method should work.  Or are you using the OCX?
What references did you add to the VB program?

mlmcc
0
 

Author Comment

by:shenlong_wc
ID: 10992783
Hi,

there is no INSERT --> PARAMETER in CR 8.5 =P

what i did was goto the report wizzard, under fields i created another a formula (eg. dateFrom ) . inside this formula, i declared a variable of the same name and returned it.

varString dateFrom := "";
dateFrom;

so i do this for every variable i need. they can be used in other portions of the report by using {@dateFrom}. not sure if this is be best way to do it, but it works for me.

now in VB i cannot use crptReport.ParameterFields(0)="Broker;TR04;true" anymore, rather i use crptReport.Formula(0).text="1/1/2004" (i'm not infront of the compiler now, so my syntax is gonna be off. explore abit yourself ^_^)

the problem to this method is that you cannot specify the variable name . if you have more than 1 variable in CR , then you have to trial and error to find out which .Formula(x) is the one you wanna use. big hassle there.

well, until i can find "parameter" option in CR , this is all i have. it works but is a pain in the a$$ to work with =p
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 10993168
There is a better way to find the formulas than trial and error.  The formula names are available to the applicationinan array and you can search for the name.  This eliminates the trial and erro and also ensures if the report changes the formula passing still works.

        For k = 1 To crRpt.FormulaFields.Count
            If (UCase$(crRpt.FormulaFields(k).Name) = UCase$(strFormulaNameToFind))) Then
                  crRpt.FormulaFields(k).Text = "ValueForTheFormula"
                  Exit For
            End If
        Next k

Glad I could help

mlmcc
0
 

Author Comment

by:shenlong_wc
ID: 11012949
oh ok, thanks !
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

756 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