Date parameter not getting passed from form to query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • beacon
    Contributor
    • Aug 2007
    • 579

    Date parameter not getting passed from form to query

    Hi everybody,

    I have a form for every report in this latest database that I use to accept parameters for the underlying query. On the form, I have a command button that launches a calendar module that I got from the Microsoft Office Access 2003: Inside and Out book by John Viescas. The calendar mod basically opens a dialog form, accepts the date chosen by the user, and passes it back to the original form.

    When I submit the form, the date doesn't get passed to the underlying query or the expression in the textbox for the report. However, if I manually type the date into the textbox on the form it works fine in both places. I thought that maybe it was because I didn't have a date format on the textboxes, but that didn't help.

    Probably should mention that the parameters are primarily for a discharge date range and then the two expressions I mentioned above that are supposed to accept the date parameter from the form.

    Form:
    Code:
    Textbox #1: BeginningDate
    Textbox #2: EndingDate
    Query:
    Code:
    DischargeDate: Between [Forms]![frmReportDefinition]![BeginningDate] And [Forms]![frmReportDefinition]![EndingDate]
    BeginningDate: [Forms]![frmReportDefinition]![BeginningDate]
    EndingDate: [Forms]![frmReportDefinition]![EndingDate]
    Report:
    Code:
    Textbox #1 Name: Title
    Textbox #1 Control Source: ="Report Definition" & Chr(13) & Chr(10) & [BeginningDate] & " to " & [EndingDate]
    If this is vague or confusing, please let me know and I'll be glad to provide more details.

    Thanks,
    beacon
  • beacon
    Contributor
    • Aug 2007
    • 579

    #2
    Well, I found a solution, but still don't really understand why what I did originally didn't work. Sorry for posting and then finding my own answer like 5 minutes later...

    I went into the query and added the CStr() function around the expression and it worked.

    I'm still interested in understanding why this happened and I was forced to use a conversion function to get it to work instead of using what I had originally, so please feel free to comment.

    Thanks,
    beacon

    Comment

    • mshmyob
      Recognized Expert Contributor
      • Jan 2008
      • 903

      #3
      Dates in Access have to wrapped in the '#' symbol.

      cheers,

      Comment

      • beacon
        Contributor
        • Aug 2007
        • 579

        #4
        Which line above would I wrap the '#' sign around? I tried using it in the query, but received a syntax error if I placed it around the entire [Forms]![ReportDef]![BeginningDate] and when I placed them around just [BeginningDate] ([Forms]![ReportDef]!#[BeginningDate]#).

        The user won't know (and probably couldn't be trusted) to put '#' around his/her date on the form, and the calendar mod returns the a date.

        Comment

        Working...