Date Filter in VBA

  • Thread starter Thread starter Jacinda
  • Start date Start date
J

Jacinda

Hi, I was hoping someone could help me out with a code I am writing…. I got
this code from the Issues database template available from Microsoft. I
adopted the code into our database for the most part, but I can not seem to
get the date part of this code to work:



' If Opened Date From

If IsDate(Me.OpenedDateFrom) Then

' Add it to the predicate - exact

strWhere = strWhere & " AND " & "Issues.[Opened Date] >= " &
GetDateFilter(Me.OpenedDateFrom)

ElseIf Nz(Me.OpenedDateFrom) <> "" Then

strError = cInvalidDateError

End If



' If Opened Date To

If IsDate(Me.OpenedDateTo) Then

' Add it to the predicate - exact

strWhere = strWhere & " AND " & "Issues.[Opened Date] <= " &
GetDateFilter(Me.OpenedDateTo)

ElseIf Nz(Me.OpenedDateTo) <> "" Then

strError = cInvalidDateError

End If





I realize that “GetDateFilter†is something I have to set… but I’m not
sure where to put the following code…



Function GetDateFilter(dtDate As Date) As String




Please, any help you can give me would be great
 
Create a new module (not a class module nor a module associated with a form
or report) and copy the code for GetDateFilter into that module.

Make sure you do not name the module GetDateFilter when you save it: modules
cannot have the same names as functions or subs.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Jacinda said:
Hi, I was hoping someone could help me out with a code I am writing.. I
got
this code from the Issues database template available from Microsoft. I
adopted the code into our database for the most part, but I can not seem
to
get the date part of this code to work:



' If Opened Date From

If IsDate(Me.OpenedDateFrom) Then

' Add it to the predicate - exact

strWhere = strWhere & " AND " & "Issues.[Opened Date] >= " &
GetDateFilter(Me.OpenedDateFrom)

ElseIf Nz(Me.OpenedDateFrom) <> "" Then

strError = cInvalidDateError

End If



' If Opened Date To

If IsDate(Me.OpenedDateTo) Then

' Add it to the predicate - exact

strWhere = strWhere & " AND " & "Issues.[Opened Date] <= " &
GetDateFilter(Me.OpenedDateTo)

ElseIf Nz(Me.OpenedDateTo) <> "" Then

strError = cInvalidDateError

End If





I realize that "GetDateFilter" is something I have to set. but I'm not
sure where to put the following code.



Function GetDateFilter(dtDate As Date) As String




Please, any help you can give me would be great
 
Back
Top