VB Textbox Passing Date Parameter to Crystal Report

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
bookspanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EwaldLCommented:
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
frodomanCommented:
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
frodomanCommented:
EwaldL - Did CRAXDRT exist in CR7?  I thought that didn't come along until CR8? - Frodoman
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

bookspanAuthor Commented:
I am using Crystal 7 and CRAXDRT is not supported in V7.
What should replace ("Text1") and ("What") in your code???
bookspanAuthor Commented:
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.
frodomanCommented:
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.
EwaldLCommented:
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
bookspanAuthor Commented:
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
frodomanCommented:
Try:

CrystalReport1.ParameterFields(0) = "AsOfDate;" & cdate(txtAsOfDate(0).Text) & ";true"
bookspanAuthor Commented:
I've got the Same error message
bookspanAuthor Commented:
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
frodomanCommented:
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"

bookspanAuthor Commented:
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
bookspanAuthor Commented:
Let's resume this tomorrow.
Thanks everyone.
Bookspan
frodomanCommented:
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"

mlmccCommented:
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
bookspanAuthor Commented:
frodoman,
txtAsOfDate(0).Text is an array.
bookspanAuthor Commented:
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.
frodomanCommented:
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?
bookspanAuthor Commented:
Technically Correct, but I've remaned the others to suite other controls
frodomanCommented:
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.
bookspanAuthor Commented:
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??
frodomanCommented:
CrystalReport1.ParameterFields(0) = "AsOfDate;" & FormatDateTime(CDate(txtAsOfDate(0).Text),1)  & ";true"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bookspanAuthor Commented:
That's it! you've got the point.
That is simple isn't it!
Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.