Form Filter on Date

A

AJOLSON

I am trying to sort from my combo box to a field named StartDate in my form.
Trying to filter to a particular date. However I get the following error
message Data mismatch in Criteria. Tthen when I debug the Me.Filiteron =True
is highlighted. I figure it has something to do with expecting String data
but is getting date data instead. Any help would be appreciated
Here is the code I am using
Private Sub FilterComboBox_Click()
Me.Filter = "[StartDate] = """ & Me.ComboStartDT & """"
Me.FilterOn = True

End Sub
Thanks
Andy
 
D

Douglas J. Steele

Dates need to be delimited with #, not quotes. It's also important that they
be in a format Access will handle correctly. Since you can't be certain of
what format your users may have chosen, your best bet is:

Me.Filter = "[StartDate] = " & Format(Me.ComboStartDT, "\#yyyy\-mm\-dd\#")
 
A

AJOLSON

Perfect. Works Great
I have all Dates to be entered as Short so that I dont have to deal with the
format issue.

Thanks again
Andy

Douglas J. Steele said:
Dates need to be delimited with #, not quotes. It's also important that they
be in a format Access will handle correctly. Since you can't be certain of
what format your users may have chosen, your best bet is:

Me.Filter = "[StartDate] = " & Format(Me.ComboStartDT, "\#yyyy\-mm\-dd\#")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


AJOLSON said:
I am trying to sort from my combo box to a field named StartDate in my
form.
Trying to filter to a particular date. However I get the following error
message Data mismatch in Criteria. Tthen when I debug the Me.Filiteron
=True
is highlighted. I figure it has something to do with expecting String
data
but is getting date data instead. Any help would be appreciated
Here is the code I am using
Private Sub FilterComboBox_Click()
Me.Filter = "[StartDate] = """ & Me.ComboStartDT & """"
Me.FilterOn = True

End Sub
Thanks
Andy
 
D

Douglas J. Steele

Don't assume that just because you entered the dates one way that they will
be displayed that way.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


AJOLSON said:
Perfect. Works Great
I have all Dates to be entered as Short so that I dont have to deal with
the
format issue.

Thanks again
Andy

Douglas J. Steele said:
Dates need to be delimited with #, not quotes. It's also important that
they
be in a format Access will handle correctly. Since you can't be certain
of
what format your users may have chosen, your best bet is:

Me.Filter = "[StartDate] = " & Format(Me.ComboStartDT,
"\#yyyy\-mm\-dd\#")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


AJOLSON said:
I am trying to sort from my combo box to a field named StartDate in my
form.
Trying to filter to a particular date. However I get the following
error
message Data mismatch in Criteria. Tthen when I debug the Me.Filiteron
=True
is highlighted. I figure it has something to do with expecting String
data
but is getting date data instead. Any help would be appreciated
Here is the code I am using
Private Sub FilterComboBox_Click()
Me.Filter = "[StartDate] = """ & Me.ComboStartDT & """"
Me.FilterOn = True

End Sub
Thanks
Andy
 
A

AJOLSON

Oh Ok thanks so much for the help.

Douglas J. Steele said:
Don't assume that just because you entered the dates one way that they will
be displayed that way.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


AJOLSON said:
Perfect. Works Great
I have all Dates to be entered as Short so that I dont have to deal with
the
format issue.

Thanks again
Andy

Douglas J. Steele said:
Dates need to be delimited with #, not quotes. It's also important that
they
be in a format Access will handle correctly. Since you can't be certain
of
what format your users may have chosen, your best bet is:

Me.Filter = "[StartDate] = " & Format(Me.ComboStartDT,
"\#yyyy\-mm\-dd\#")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I am trying to sort from my combo box to a field named StartDate in my
form.
Trying to filter to a particular date. However I get the following
error
message Data mismatch in Criteria. Tthen when I debug the Me.Filiteron
=True
is highlighted. I figure it has something to do with expecting String
data
but is getting date data instead. Any help would be appreciated
Here is the code I am using
Private Sub FilterComboBox_Click()
Me.Filter = "[StartDate] = """ & Me.ComboStartDT & """"
Me.FilterOn = True

End Sub
Thanks
Andy
 

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

Similar Threads


Top