Using a variable with DoCmd.ApplyFilter (1 Viewer)

Howie Jones

Registered User.
Local time
Today, 19:44
Joined
Aug 14, 2003
Messages
15
Hi again

I want to replicate the 'Filter by selection' menu functionality in VBA to filter to the current record only.

DoCmd.ApplyFilter appears to only accept text as the = part of the argument.

If I Dim and set a variable CurRec to = SCOFull (a serial number that is unique to a given record)

DoCmd.ApplyFilter , SCOfull = CurRec - filters to include all of the records

DoCmd.ApplyFilter , "SCOfull = CurRec" - thinks CurRec is an undefined variable and pops up a dialogue box for you to type it in.

DoCmd.ApplyFilter , "SCOfull = 'CurRec'" - filters to a new record

What am I doing wrong? Or does DoCmd.ApplyFilter only work with a string input?

Regards

Howie
 

namliam

The Mailman - AWF VIP
Local time
Today, 20:44
Joined
Aug 11, 2003
Messages
11,695
if its a number:

"SCOfull = "& CurRec

If its text:

"SCOfull = '"& CurRec & "'"

Regards
 

SilentBreaker

Registered User.
Local time
Today, 19:44
Joined
Aug 7, 2003
Messages
28
Or

If its text:

"SCOfull = " & Chr(34) & CurRec & Chr(34)

:D
 

Users who are viewing this thread

Top Bottom