Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass vb variable to parameter in CR in runtime? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello,

I got trouble in this topic. So I hope all of you could have greatly help.

In my VB Project, there is a textbox(txt1) and a command button(cmd1) in a form(form1).

Also, I add a CrystalReport into my project so that there are another form(form2) and
a report(crystal1.dsr) which the database is ready in my project.

Now,form2 have the following code:

Dim Report As New Crystal1

Private Sub Form_Load()
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub

for the crystal.dsr, I've made a parameter "CUSTID" for asking user to imput customer's id.
I want the program is that, when user imput the customer's id in txt1 and click cmd1, the value in
txt1 will pass to parameter so that the reprt will only show this customer information.

i saw alot newsgroup said that report1.ParameterFields(0) = "CUSTID;" & Txt1.Text & ";true",
but i can't work with this code.

how can i do this?

Thanks you,
Calvin
 
report1.parameterfields(0) ... is the way to pass params if you are using the OCX (i.e., the old way of doing things). The object Report1 would be an instance of the OCX (not improved or updated since V6).

Use this code instead (assuming Report is the name of your object instance):

Report.ParameterFields.Item(1).AddCurrentValue txt1.txt

And don't forget to login to the server...
Brian J. Alves
Terrier Consulting, Inc.
Email: brian.alves@worldnet.att.net
VB / Crystal / SQLServer
 
How to login to the server?
could you show the vb code?
and do i need to logoff after print a report?

thank you,
calvin
 
also, if i use old method, how to show a report?

thanks alot,
calvin
 
In short,how to pass the variable form vb textbox to parameter in RDC?
 
To login to the server before you attempt to view the report (again, assuming Report is the name of your object):

Report.Database.LogOnServer "p2sodbc.dll", "put DSN here", "put db name here", "user id here", "password here"

If you run your code without logging into the server, you should get a "Server not opened" error message. You will also get this message if you don't pass the params to .LogOnServer correctly.

Try not to go back to the OCX because Crystal isn't updating it anymore. Brian J. Alves
Terrier Consulting, Inc.
Email: brian.alves@worldnet.att.net
VB / Crystal / SQLServer
 
I got the solution!
Dim abc As Date
Dim Report As New CrystalReport1
Dim crxParameters As CRAXDRT.ParameterFieldDefinitions
Dim crxParameter As CRAXDRT.ParameterFieldDefinition
CRViewer1.ReportSource = Report
Set crxParameterFields = Report.ParameterFields
Set crxParameterField = crxParameterFields.Item(1)
abc = "2/5/2001"
crxParameterField.SetCurrentValue abc
CRViewer1.ViewReport

thank you!
But as sam as above, all types of abc (ie string,integer)can work except date type.Could anyone know about this?
 
Hi - I am trying to pass a value from Access database to Crystal Reports. I have tried to work with the code above, but to no avail. The code I am currently using to open the report from Access is as follows:

Public Function CrystalReport(ByVal frmformthisform As Form, ByVal strReport As String)

appCR.WindowTitle = "Crystal Report"
appCR.ReportFileName = strReport
appCR.WindowState = crptMaximized
appCR.Destination = crptToWindow
appCR.WindowShowGroupTree = False
appCR.WindowShowPrintBtn = True
appCR.WindowShowRefreshBtn = True
appCR.Action = 1

End Function

Can you tell me how to accomplish passing a value to Crystal?

Thanks!

M.
 
Also, I am using the OCX. I use this line of code:

appCR.ParameterFields(0) = strDate

and it tells ma that method action of CrystalCtrl failed.

Why is it doing that? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top