Results 1 to 2 of 2
  1. #1
    Tambe257 is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Mar 2017
    Posts
    28

    Search on a form that is filtered with a combobox

    I have a form called LookUpByStore that displays records from a query. The records are products that we carry in our chain of retail stores. I have a combobox at the top of the form called StoreCombo that lists the store numbers as text. ("109", "111", etc.)



    I have a textbox called txtSearch and a button called SearchBtn. I wrote the code below to fetch the store number from the StoreCombo and then search for products within that store only. The columns involved are:

    StoreNum - which is chosen in the combobox

    and then I need to search these three columns for whatever is entered in the textbox:
    ItemNameWeight - which is a text field
    ItemNum - which is a number
    ItemUPCCode - which is text

    Here is my code currently, which I understand searches the ItemNameWeight AND sets the StoreNum, while the ItemNum and ItemUPCCode are searched without the storenum being set. I had this set as a macro, which worked, but I need to add the StoreNum to the other two fields as well, so it will go over the 255 character limit for macros.

    [StoreNum]=[Forms]![LookupByStore]![StoreCombo] And [ItemNameWeight] Like"*"& [Forms]![LookupByStore]![txtSearch] &"*"Or [ItemNum] Like"*"& [Forms]![LookupByStore]![txtSearch] &"*"Or [ItemUPCCode] Like"*"& [Forms]![LookupByStore]![txtSearch]

    I tried to move the code to VBA like this:

    Private
    Sub SearchBtn_Click()
    DoCmd
    .ApplyFilter , [StoreNum] = [Forms]![LookupByStore]![StoreCombo] And [ItemNameWeight] Like"*"& [Forms]![LookupByStore]![txtSearch] &"*"Or [ItemNum] Like"*"& [Forms]![LookupByStore]![txtSearch] &"*"Or [ItemUPCCode] Like"*"& [Forms]![LookupByStore]![txtSearch] &"*"
    EndSub

    But this gives me an error 2427 "You entered an expression that has no value"

    A) What am I doing wrong

    and

    B) What is the best practice to add StoreNum to the other two columns in VBA, because I know writing, "[StoreNum] = [Forms]![LookupByStore]![StoreCombo] And " each time is not the correct way to do it.

    Thanks, Tony



  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,815
    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: 8
    Last Post: 09-14-2015, 09:38 PM
  2. Replies: 9
    Last Post: 03-26-2015, 04:20 PM
  3. Replies: 1
    Last Post: 12-10-2013, 03:15 PM
  4. Search Form with Combo Box - Filtered
    By Varda in forum Forms
    Replies: 6
    Last Post: 06-14-2013, 07:24 PM
  5. Combobox Filtered Search
    By dgwynn in forum Access
    Replies: 3
    Last Post: 12-12-2012, 03:10 PM

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