Results 1 to 4 of 4
  1. #1
    baronqueefington is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    32

    Using Combo boxes as search criteria ? (Allen Browne - Search code)


    Hello again,

    I have created a search form based upon Allen Brownes search code - http://www.allenbrowne.com/ser-62.html

    I have it up and running and the text search box's work brilliantly, but I now wish to add a combo box into the criteria string, which is causing me problems. My code is

    If Not IsNull(Me.cboBiaName) Then
    strWhere = strWhere & "([BIA Name] = "" & Me.cboBiaName & "") AND "
    End If

    I have the combo box in the header, which when clicked shows the correct list, but once a criteria is selected search brings back no records. If I leave it blank and enter criteria in the other text search boxes the search runs correctly.

    The database is made up of 3 tables a main table, which the search form is generated from and 2 list tables.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What is the RowSource of the combobox? Does it include an ID field? Is the actual value of combobox the ID?

    Have you set lookups with alias in table? http://access.mvps.org/access/lookupfields.htm What data type is [BIA Name]?

    If [BIA Name] is a text field and actually has descriptive text value (not ID) then look at Allen's code again for text type field. It doubles the quote mark for text delimiter. An alternative is an apostrophe.

    strWhere = strWhere & "([BIA Name] = '" & Me.cboBiaName & "') AND "
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    baronqueefington is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    32
    Thank you! Replacing two of the quotations and replacing them with apostrophe's solved it! Are you able to explain why that did it?

    Thanks again.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If you want a quote mark to be recognized as a literal character between two other quote marks, the quote mark must be doubled. This is called escaping a special character. Sometimes doubling a special character will escape it, sometimes using a \ before a special character will escape it. This concept is common to all programming languages. However, the \ won't work for constructing an SQL statement in VBA. An apostrophe between quotes will be recognized as a text delimiter as long as they are in pairs - one on each side of the text parameter. Solo apostrophes such as can be found in some data (O'Conner, O'Hare, etc) can cause issue. Say you wanted to use LastName as filter criteria and it is possible some names will have an apostrophe, need to manage that possibility.

    strWhere = strWhere & "([LastName] = '" & Replace(Me.cboLastName, "'", "''") & "') AND "
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-29-2014, 03:23 PM
  2. Replies: 15
    Last Post: 11-20-2013, 04:30 PM
  3. Allen Browne Ranking Sample?
    By kwooten in forum Queries
    Replies: 1
    Last Post: 05-17-2013, 04:42 PM
  4. Need a little help with Allen Browne code
    By NewtoIT in forum Programming
    Replies: 16
    Last Post: 05-09-2012, 04:50 PM
  5. Search using combo boxes
    By jakeao in forum Access
    Replies: 0
    Last Post: 05-18-2011, 12:17 PM

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