Link to home
Start Free TrialLog in
Avatar of diek_nf
diek_nfFlag for Canada

asked on

Wanted: VB SQL Expert

Please step up to the plate,
I want to allow users to enter the reporting period( date to date) for a Crystal Reports Active X comp. ver 6. using a dialogue form to pass a sql query via a string argument.

 The sql for crystal reports is slightly different than vb sql, so my books are not helping.

I am using the Record Selection Formula Editor(Crystal Reports), to enter the following formula:
"{ClientInteraction.Date_Interaction} in "  &  txt_FromDate.Text &    "  to  " & txt_ToDate.Text
---------------------------------------
the report is displayed in a vb form via a CRViewer1 object.

The editor generates an error:
"The remaining text does not appear to be part of the formula" , it places the cursor --> &  txt_FromDate.Text &    "  to  " & txt_ToDate.Text
=======================================
Thank you.

Avatar of Dalin
Dalin

Try:
"{ClientInteraction.Date_Interaction} in' "  &  txt_FromDate.Text &    "'  to ' " & txt_ToDate.Text  & "' "
If you really want to be independant from your regional settings, use the
following statement :

"{Acts.PublishingDate} = Date (2000, 12, 31)"



ASKER CERTIFIED SOLUTION
Avatar of brice123
brice123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of diek_nf

ASKER

Brice123,
Please don't get pissed, like some other guy after I rejected his answer. First, I am uncertain what region settings have to do with users entering two dates.

Second,your other answer may work but when you answer a question, as opposed to commenting, you lock the question until I evaluate it. I will try your second comment. Again please do not get mad.
diek
What database are you using? In most databases you have to put special characters around a date constant in an SQL statement. In access you use the "#" (pound) sign, in DB2 you use a single quote. I would try formatting the date and wrapping it.

"{ClientInteraction.Date_Interaction} in #" & Format(txt_FromDate.Text, "MM/DD/YYYY") & "#  to #" & Format(txt_ToDate.Text, "MM/DD/YYYY") & "#"

The pound sign may not be the correct character for your DBMS but I think you get the idea.


Avatar of diek_nf

ASKER

prozak and others,
I got to work on another area for a few hours so I won't have the chance to try your comments until later today. I will try everyones code. I'll be back. Thanks.
diek
diek,

I definitively recommend to use the next syntax. You will be independant from the date format used by the underlying database.

dim dtmFrom as date
dim dtmTo as date
dim strFormula as string

if IsDate(txt_FromDate) then
  dtmFrom = CDate(txt_FromDate)
end if

if IsDate(txt_ToDate) then
  dtmTo = CDate(txt_ToDate)
end if

strFormula = "{ClientInteraction.Date_Interaction} in Date(" & Year(dtmFrom) & "," & Month(dtmFrom) & "," & Day(dtmFrom) & ") to Date(" & Year(dtmTo) & "," & Month(dtmTo) & "," & Day(dtmTo) & ")"

crViewer1.SelectionFormula=strFormula
Avatar of diek_nf

ASKER

Brice,
I am passing the strFormula as a global and I know it is getting passed to my the form with my crviewer, as {ClientInteraction.Date_Interaction} in Date(14,3,1960) to Date(30,12,1999). Through a Msgbox asa tes.

 It still isn't restricting the dates however.

Thanks for not getting pissed when I rejected your last note , how would I get:
"{Acts.PublishingDate} = Date (2000, 12, 31)"
to display Dec as opposed to 12.
Avatar of diek_nf

ASKER

Brice,
I am only doing this to unlock the question and because that didn't work.
diek
Avatar of diek_nf

ASKER

Hi,
if anyone is still interested I am still in need of assistance.
diek
Avatar of diek_nf

ASKER

I revisited this solution and it worked. Thank you.
diek