Solved

VB Textbox Passing Date Parameter to Crystal Report

Posted on 2003-11-25
24
12,491 Views
Last Modified: 2007-12-19
Hi,
How to you pass a date as a parameter to Crystal Report from VB textbox. Note that the date is entered at run-time by the user and should be display on the report header. The date is not associated with any table of the datebase.
I am using VB6 and Crystal 7
Thanks for your help.
Bookspan
0
Comment
Question by:bookspan
  • 12
  • 9
  • 2
  • +1
24 Comments
 
LVL 13

Expert Comment

by:EwaldL
Comment Utility
if the value has no relation to the report design / processing, then you could place a text box in the report header and change it's value accoring to what was entered inot the vb textbox

  Dim crTextObject As CRAXDRT.TextObject
  Set crTextObject = crReport.Sections("RH").ReportObjects.Item("Text1")
  crTextObject.SetText ("what")

otherwise, you could always create a date parameter in the report, place it in the report header and populate it at runtime using the setcurrentvalue function
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Bookspan,

Is this the same report we've been talking about for 2 days? :-)

You want to add a parameter to your report, then just drag the parameter field into your header.  From VB send the parameter over exactly like you were doing for the selection criteria parameter.

This is really the same process that we worked through earlier.  The only difference is you're just displaying this parameter on the report instead of using it for selection criteria.

Note that you may need to use cdate() on the textbox.value when you send it to make sure it's date formatted correctly.

Cheers,

Frodoman
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
EwaldL - Did CRAXDRT exist in CR7?  I thought that didn't come along until CR8? - Frodoman
0
 

Author Comment

by:bookspan
Comment Utility
I am using Crystal 7 and CRAXDRT is not supported in V7.
What should replace ("Text1") and ("What") in your code???
0
 

Author Comment

by:bookspan
Comment Utility
Frodoman,
This is another report and the difference here is that the date field is not coming from any table. it is just coming from VB textbox. I've tried to implement what we did before, but it is not working with thos one.
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
That shouldn't matter too much.

Create a parameter exactly as before and name it TheDate.  Now add the parameter to your report header (just drag & drop).  That's it on the Crystal Side.

On the VB end, it's nearly identical to before:  CrystalReport1.ParameterFields(0) = "TheDate;" & YOURTEXTBOX.Text & ";true"


If it's not working, let me know where & what.
0
 
LVL 13

Expert Comment

by:EwaldL
Comment Utility
frodoman,
the craxdrt.dll was part of version 7, even version 6.

bookspan,
why do you think the craxdrt.dll is not supported in version 7?

("Text1")  needs to be the name of the field. i dont think it is visible in v.7, only in 9.
try using an index, ie Set crTextObject = crReport.Sections("RH").ReportObjects.Item(1)
Then do a msgbox.show crTextObject.Name to get the correct string

("what") needs to be the value captured by your application
0
 

Author Comment

by:bookspan
Comment Utility
I am having a Invalid Parameter field value and CrystalReport1.Action = 1 is highlited.
You have mentioned something about cDate()???

Below is my code:

Private Sub ArByPayor_Click()
If ChkBadDebt(0).Value = 1 Then
CrystalReport1.ParameterFields(0) = "AsOfDate;" & txtAsOfDate(0).Text & ";true"
CrystalReport1.ReportFileName = App.Path & "\ArCalculatedNetArByPayorIncludingAllowCalcsBDebt.rpt"
Else
If ChkPayorSum(1).Value = 1 Then
CrystalReport1.ReportFileName = App.Path & "\ArCalculatedNetArByPayorIncludingAllowCalcsSummary.rpt"
Else
CrystalReport1.ReportFileName = App.Path & "\ArCalculatedNetArByPayorIncludingAllowCalcs.rpt"
End If
End If
CrystalReport1.Action = 1

End Sub
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Try:

CrystalReport1.ParameterFields(0) = "AsOfDate;" & cdate(txtAsOfDate(0).Text) & ";true"
0
 

Author Comment

by:bookspan
Comment Utility
I've got the Same error message
0
 

Author Comment

by:bookspan
Comment Utility
EwalDL,
at variable declaration of crTextObject, I couldn't find CRAXDRT anywhere in the popups method.
I am new to VB and want simple solutions
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Bookspan - In Crystal, what is the type of your parameter field that you created?  That will dictate how you need to send the value.

If it's date: CrystalReport1.ParameterFields(0) = "AsOfDate;" & cdate(txtAsOfDate(0).Text) & ";true"

If it's text/string: CrystalReport1.ParameterFields(0) = "AsOfDate;""" & txtAsOfDate(0).Text & """;true"   <-- Note the triple quote combinations

If numeric: CrystalReport1.ParameterFields(0) = "AsOfDate;" & cint(txtAsOfDate(0).Text) & ";true"

0
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

 

Author Comment

by:bookspan
Comment Utility
AsOfDate is set as Date. and I've used
CrystalReport1.ParameterFields(0) = "AsOfDate;" & cdate(txtAsOfDate(0).Text) & ";true"
In VB the txtAsOfDate is formated as Date m/d/yy
0
 

Author Comment

by:bookspan
Comment Utility
Let's resume this tomorrow.
Thanks everyone.
Bookspan
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Is txtAsOfDate an array or is it just a control on it's own?  Unless it's part of an array you should be using:

CrystalReport1.ParameterFields(0) = "AsOfDate;" & cdate(txtAsOfDate.Text) & ";true"

0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
To use CRAXDRT you need to add a reference to it in your project.

By the method of parameter passing it appears you are using the OCX so you don't need CRAXDRT which is for the RDC.

Another method is to use a formula and set it from VB.
CrystalReport1.Formulas(0) = "'" & txtAsOfDate.Text & "'"

mlmcc
0
 

Author Comment

by:bookspan
Comment Utility
frodoman,
txtAsOfDate(0).Text is an array.
0
 

Author Comment

by:bookspan
Comment Utility
mlmcc,
with CrystalReport1.Formulas(0) = "'" & txtAsOfDate.Text & "'"
Crystal prompts for input data. I don't want that. I want VB to pass directly the value to Crystal.
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Is it an array of string or it is an array of controls?  

CrystalReport1.ParameterFields(0) = "AsOfDate;" & cdate(txtAsOfDate(0).Text) & ";true"

The above code means you have more than one text box named txtAsOfDate.  Is that correct?
0
 

Author Comment

by:bookspan
Comment Utility
Technically Correct, but I've remaned the others to suite other controls
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
You might want to consider changing your crystal parameter to "string" format and removing the 'cdate' to see how it works.  A string format parameter can accept virtually anything so as long as something is being passed it should work.
0
 

Author Comment

by:bookspan
Comment Utility
I just did it. I have changed it to string and used
CrystalReport1.ParameterFields(0) = "AsOfDate;" & CDate(txtAsOfDate(0).Text) & ";true"
it returns the date as is from the VB textbox. for example 08/31/03 displays as 08/31/03 on the report.
The only problem is that the report should display something like this" Wednesday August 31, 2003"
Is there another function apart of CDate to convert dates??
0
 
LVL 42

Accepted Solution

by:
frodoman earned 50 total points
Comment Utility
CrystalReport1.ParameterFields(0) = "AsOfDate;" & FormatDateTime(CDate(txtAsOfDate(0).Text),1)  & ";true"

0
 

Author Comment

by:bookspan
Comment Utility
That's it! you've got the point.
That is simple isn't it!
Thanks.
0

Featured Post

Highfive Gives IT Their Time Back

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!

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

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

8 Experts available now in Live!

Get 1:1 Help Now