Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / July 2005

Tip: Looking for answers? Try searching our database.

filter multiple criteria with "or"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tgl - 26 Jul 2005 20:48 GMT
I'm trying to have a command button look up based on 2 criteria based on
first & last names.  Works fine if I'm doing one or the other:

Dim FIRSTNAMEEXPR As Variant
Dim LASTNAMEEXPR As Variant

(the FIRSTNAMEEXPR and LASTNAMEEXPR are expressions that I have (work fine)
that have pared down names to get rid of middle initials, Jr., Sr. etc.... I
didn't put whole thing here)

Me.Filter = "[first] Like'" & FIRSTNAMEEXPR & "'" And "[last] Like'" &
LASTNAMEEXPR & "'"
Me.FilterOn = True

also, is there a way to do "Or"?

Many thanks!

Signature

tgl

Sprinks - 26 Jul 2005 21:06 GMT
Hi, tgl.

AND needs to be part of your string expression that you set the filter to.  
Rearrange your quotes so that it is cast as a string literal:

 Me.Filter = "[First] Like'" & FIRSTNAMEEXPR & "' And [Last] Like'" & _
               LASTNAMEEXPR & "'"
 Me.FilterOn = True

Hope that helps.
Sprinks

> I'm trying to have a command button look up based on 2 criteria based on
> first & last names.  Works fine if I'm doing one or the other:
[quoted text clipped - 13 lines]
>
> Many thanks!
Sprinks - 26 Jul 2005 21:07 GMT
tgl,

Forgot to mention, you can use OR the same way.

Sprinks

> I'm trying to have a command button look up based on 2 criteria based on
> first & last names.  Works fine if I'm doing one or the other:
[quoted text clipped - 13 lines]
>
> Many thanks!
fredg - 26 Jul 2005 21:07 GMT
> I'm trying to have a command button look up based on 2 criteria based on
> first & last names.  Works fine if I'm doing one or the other:
[quoted text clipped - 13 lines]
>
> Many thanks!

Too many double quotes.
I've added a space between the single and double quotes for clarity.
Remove the spaces when using the code. Also add a space after Like and
the ' so Access recognizes the word.

Me.Filter = "[first] Like ' " & FIRSTNAMEEXPR &  " ' And [last] Like
' " &  LASTNAMEEXPR & " ' "
Me.FilterOn = True
Signature

Fred
Please only reply to this newsgroup.
I do not reply to personal email.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.