Date Filter in VBA

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
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top