This topic is locked
[SOLVED]

 Date Comparison in Add Page Before Display

9/3/2010 9:53:20 AM
ASPRunnerPro General questions
J
Jay123 author

Hi!
I am using ASPRunner 6.1.
I have this code in Add Page Before Display.

=============================================================

dim rsExistsB

set rsExistsB = dal.Table("Presentation Schedule").Query("RegistrationStartDate>'" CDate (DateAdd("d",-1,Now())) & "'","")

if not rsExistsB.eof then

Flush_output

Response.Write "<script>alert('Sorry, the registration has not started yet for the upcoming event!')</script>"

end if

rsExistsB.Close : set rsExistsB = Nothing

=============================================================
I keep on getting this error message: Expected ')'
Could you pls. advise how can I correct my code above?
Thanks,

Jay

Admin 9/7/2010

The following line misses an ampersand:

set rsExistsB = dal.Table("Presentation Schedule").Query("RegistrationStartDate>'" CDate(DateAdd("d",-1,Now())) & "'","")
try this:

set rsExistsB = dal.Table("Presentation Schedule").Query("RegistrationStartDate>'" & CDate(DateAdd("d",-1,Now())) & "'","")

J
Jay123 author 9/9/2010

Hi Sergey,
Thanks for the reply.
I am now getting a different error message: Data type mismatch in criteria expression.
I've tried several ways to fix it (ie. I have added CDate on the RegistrationstartDate, etc.) but no luck. On my database, the RegistrationstartDate was set to Date/Time.
Your assistance is very much appreciated.
Thanks,

Jay

Admin 9/9/2010

Jay,
you need to print WHERE clause on the page before executing SQL query i.e.

Response.Write "RegistrationstartDate>'" & CDate(DateAdd("d",-1,Now())) & "'"


Correct date format in SQL is yyyy-mm-dd.

J
Jay123 author 9/9/2010

Hi Sergey,
I have changed the date format of the RegistrationstartDate on the Editor as YYYY-MM-DD.
I have added the "response.write" before the syntax for SQL query like this:

=================================================================================

Response.Write "RegistrationstartDate>'" & CDate(DateAdd("d",-1,Now())) & "'"
dim rsExistsB

set rsExistsB = dal.Table("Presentation Schedule").Query("RegistrationstartDate>'" & CDate (DateAdd("d",-1,Now())) & "'","")

if not rsExistsB.eof then

Flush_output

Response.Write "<script>alert('Sorry, the registration has not started yet for the upcoming event!')</script>"

end if

rsExistsB.Close : set rsExistsB = Nothing

=================================================================================
I guess I didn't quite understand your suggestion and I'm still getting the "data type mismatch" error. Could you pls. tell me where should I put what?
There's one thing that I have tried, though. I've changed the data type of RegistrationstartDate to "text" on my MS Access database. The error went away but the logic became incorrect. The alert pops up regardless of the registration date I entered (before, equal or after the current date). I have expected that because it was set as a "text".
I really need to make the system recognize the RegistrationstartDate as a "date" to make the comparison with current date works.
Thanks,

Jay

Admin 9/9/2010

Jay,
what's your Response.Write statement prints?
Date format needs to be changed in your event code. You need to modify your code so it builds the following WHERE clause:

RegistrationstartDate > '2010-09-09'
J
Jay123 author 9/9/2010



Jay,
what's your Response.Write statement prints?
Date format needs to be changed in your event code. You need to modify your code so it builds the following WHERE clause:

RegistrationstartDate > '2010-09-09'


J
Jay123 author 9/9/2010

Hi Sergey,
The print that I am getting is 'RegistrationstartDate>2010-09-09'
I forgot to mention. The RegistrationstartDate is actually from another table which will be called through lookup. If "yes" is selected from one of the fields, the registration start date (a lookup field) will be displayed.
I'm not sure if this makes a difference. What I've noticed, if I will not enter a registration start date from the source table, I'm not getting an error. The 'RegistrationstartDate>2010-09-09' gets printed on the page. However, when I enter the registration start date from the source table, that's when I am getting that "data type mismatch" error.
Thanks,

Jay

J
Jay123 author 9/10/2010

Hi Sergey,
I finally got it to work. Thanks a lot for your assistance.
Here's what I did:

  1. In MS Access database, the data type of RegistrationstartDate remains "date/time".
  2. In ASP Runner, on Editor tab, I set the RegistrationstartDate format to YYYY-MM-DD.
  3. In ASP Runner, on Add Page Before Display event, I have this syntax:

    ===================================================================================================

    set rsExistsBB = dal.Table("Presentation Schedule").Query("RegistrationStartDate>CDate(Date())","")

    ===================================================================================================
    The culprit was the 'DateAdd("d",-1,Now())'. After changing it to 'Date()' and removing the unnecessary characters (ie. &, '), it finally worked.
    Thanks a lot again for your time in looking into this!
    Regards,

    Jay