Problem with unbound form fields for search / building query in VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cdhaynes
    New Member
    • Mar 2008
    • 3

    Problem with unbound form fields for search / building query in VBA

    Hi, I am using unbound text boxes in the header of a form to allow the user to search on a number of fields. I am using VBA to build a query string based on these and it has been fine when comparing text fields on the main form but I have run in to trouble comparing date/time fields on a subform.
    The subform is called Activity and I am comparing to the date/time field ActivityStartDa te.

    This is the code:
    Code:
    If Not IsNull(Me.searchFromDate) Then
            varFromDate = Format(Me.searchFromDate, "mm/dd/yyyy hh:nn:ss")
            strWhere = strWhere & "([Activity].Form![ActivityStartDate] >= " & varFromDate & ") AND "
            End If
    (There is code later on to remove the trailing AND if it is at the end)

    This gives me the error:
    Run-time error 3075 Syntax error (missing operator) in query expression
    '([Activity].Form![ActivityStartDa te] >= 02/12/2008 00:00:00)'

    I've tried printing ActivityStartDa te and it's exactly the same date and format.
    As the operator does seem to be there I can't see why I get this error message - can anyone shed any light?

    Using Access 2007 on Windows Vista.

    Thanks in advance
    Craig
  • cdhaynes
    New Member
    • Mar 2008
    • 3

    #2
    Sorry, just needed to format the date fields with the # (hash) symbols either side. Noob mistake, my bad.

    Comment

    Working...