Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Docmd.ApplyFilter does not work

Status
Not open for further replies.

jofet

MIS
Sep 3, 1999
32
PH
i have this form to open with an underlying table, i need to filter out the record before it shows but it does not work.


Private Sub Form_Open(Cancel As Integer)
Dim Mystr As String
On Error GoTo Error

Mystr = Left(Format(Now(), "dddd"), 3)
If Mystr = "Mon" Then
DoCmd.ApplyFilter , [Days] Like "*2*"
End If
Exit Sub
Error:
MsgBox Err.Description

End Sub


i need to filter out the [Days] field with any number containing "2", but the ApplyFilter does not work, it shows "filtered" on the record navigation but it still show all the records in the table why is that? please help.
 

You need a slight syntax correction.

Examples:

DoCmd.ApplyFilter , "[days] like '*2*'"

If [days] represents an integer (Monday is day of the week 2) then the syntax would be...

DoCmd.ApplyFilter , "[days] = 2"

If [days] is text but contains a single character the preferred syntax is...

DoCmd.ApplyFilter , "[days] = '2'"

Avoid using LIKE if possible. It is not as efficient as an equality test. Terry
------------------------------------
Blessed is the man who, having nothing to say, abstains from giving us worthy evidence of the fact. -George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top