Function of Filtering!

  • Thread starter Thread starter Sam Hung
  • Start date Start date
S

Sam Hung

Hi All,

Last time the question I posted here about the function of
filtering. I tried it and found another troubles and the
code is as follows:
If KeyCode=13 Then
Me.Filter="table.date_field between '" & Trim
(text1.text) & "' and '" & Trim(text2) & "'"
Me.FilterOn=True
End If

Table Name: Table text1 datatype: Short Date
Column Name: date_field text2 datatype: Short Date
Datatype: Date/Time

I'm expecting to filter the data according to the date
filled in text1 and text2.

The error message is like:
You cannot refer to the control properties or methods
unless that control properties has the point...

So what's the problem with my code? I guess it is probably
from the different datatype.

Please help,
thanks,
Sam.
 
Sam,

You guessed your problem and with a little change to your
code, the problem will be solved. You are using string
concatenation for a numerical datatype. Try using the
following structure:

"[BirthDate] = " & Trim(Text1) & " And [BirthDate] = " &
Trim(Text2)

I hope this helps.

Alastair
 
The error message was caused by:
text1.text
Drop the ".text".

To concanate literal dates into the string for the filter, format them and
include the # delimiters:

Me.Filter = "[date_field] Between " & _
Format(Me.text1, "\#mm\/dd\/yyyy\#") & " And " & _
Format(Me.text2, "\#mm\/dd\/yyyy\#")
Me.FilterOn = True
 
Back
Top