Find Button on a Form

  • Thread starter Thread starter j
  • Start date Start date
J

j

Hello, I have a find button on a search form that I have
created using wizard and for the most part it works fine.
I can search using a person's name, address, id, etc. I
have two date fields and I want to be able to search using
the button for a range of dates. Is there any way that I
can program the find button to do that?

Thanx!!
 
The Find box cannot match a range of dates like that.

Add 2 text boxes to your form named (say) txtStartDate and txtEndDate.
Set their Format property to Short Date or similar.

Add a command button to filter the form would have something like this in
the Event Procedure for its Click event:

Private Sub cmdFilter_Click()
Dim strWhere As String
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Me.Dirty Then
Me.Dirty = False
End If

If IsDate(Me.txtStartDate) And IsDate(Me.txtEndDate) Then
strWhere = "[MyDate] Between " & _
Format(Me.txtStartDate, conJetDate) & " And " & _
Format(Me.txtEndDate, conJetDate)
Me.Filter = strWhere
Me.FilterOn = True
Else
Msgbox "Both dates required."
End If
End Sub
 
Back
Top