Results 1 to 6 of 6
  1. #1
    m_low is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    8

    Modify SQL query to account for three parameters instead of one

    Hi everyone,

    I have a search box function that works using the following code



    Code:
    SELECT *
    FROM tblArchitectureFirms
    WHERE [ArchitectureFirmName] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    OR [ArchitectureFirmType] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    OR [ArchitectureFirmAddress] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    OR [ArchitectureFirmContact] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    OR [ArchitectureFirmPhoneNumber] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    OR [ArchitectureFirmEmail] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    OR [ArchitectureFirmWebsite] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    OR [ArchitectureFirmNotes] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*";

    However i need to add two combobox paramaters to further refine results a Mailing Consent Given: Yes, no, or Null and a Solicited: yes, no, or null

    If it is selected null then i want that option ignored and for the database to search just using the other two or one paramaters.


    Click image for larger version. 

Name:	houseporndatabaseSeptember 15.png 
Views:	15 
Size:	94.5 KB 
ID:	18112


    This needs to be done in SQL as it is going on sharepoint.

    Any ideas?

    Thanks!

    Michael

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    Test all controls for a possible filter...

    Code:
    Select Case True
    Case not isnull(cboState)
        sWhere = sWhere & " and [state]='" & cboState & "'"
    Case not IsNull(txtName)
        sWhere = sWhere & " and [Name]='" & txtName & "'"
    Case not IsNull(chkContact)
        sWhere = sWhere & " and [Contact]=" & chkContact.value
    End Select
    
    sSql = "SELECT * FROM tblArchitectureFirms WHERE "
    sSql = sSql &  "[ArchitectureFirmName] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    sSql = sSql &  "OR [ArchitectureFirmType] LIKE "*" & Forms!frmArchitectureFirms!txtSearchBoxArchitectureFirms & "*"
    sSql = sSql & sWhere

  3. #3
    m_low is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    8
    Thanks! I will try this out.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You might want to check out

    Use a parameter to return all records if Null
    http://access.mvps.org/access/queries/qry0001.htm

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Further to Steve's suggestion, I am attaching some thoughts about Forms and controls. The issue of NULL and zero length strings (ZLS) is mentioned. Although not all specific to your issue, you may find some interesting tips.
    Good luck.
    Attached Files Attached Files

  6. #6
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    One limitation of [Field] OR [Field] IS NULL is optimization. If there is a search form with several search fields, all of which can be an input or can be null, the number of combinations of conditions to check causes the query to run pretty slow. I prefer to use the LIKE "*" & [Field] & "*"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 11-06-2013, 05:38 PM
  2. Modify a query
    By saray in forum Queries
    Replies: 2
    Last Post: 06-08-2013, 02:05 PM
  3. Overdue Account Query- Access 2010
    By lfarring in forum Queries
    Replies: 3
    Last Post: 06-04-2013, 03:31 PM
  4. Getting one account from 15,000
    By citygov in forum Programming
    Replies: 4
    Last Post: 10-21-2011, 02:27 PM
  5. Replies: 2
    Last Post: 02-20-2010, 01:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums