Results 1 to 3 of 3
  1. #1
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119

    Exclamation ComboBox placeholder text

    Hi everyone,
    i have 2 combobox on a form that gets their values from 2 different tables.
    The first combobox (Cbo1) as the following select statement:
    SELECT Tbl_Crops.Crop_nameFROM Tbl_Crops
    ORDER BY Tbl_Crops.Crop_name;



    The second combobox (Cbo2) has the following:
    SELECT Tbl_AFRCountries.CountryName
    FROM Tbl_AFRCountries
    ORDER BY Tbl_AFRCountries.CountryName;




    These combo boxes acts as a search boxes (a user can select a value from Cbo1 and press a "Search Button" to filter the records / OR can select a value from Cbo2 and press a "Search Button" to filter the records / OR can select values from Cbo1 and Cbo2 and then press a "Search Button" to filter the records ).

    In the OnClick Event of the "Search Button" i have the following code:
    Private Sub BT_Search_Click()
    DoCmd.OpenForm "Frm_AppRateList", acNormal, , "Crop_Name Like '" & Me.Cbo1 & "*' AND CountryName Like '" & Me.Cbo2 & "*'"
    End Sub

    Now because i had some space issue on my form, i had to get rid of the combobox label.
    And now i want Cbo1 to display "Select Crop" and Cbo2 to display "Select Country" as the default values when the user opens the form.

    What i did at first, was setting the default values for both combox boxes in the Property sheet.
    However when i select a value from Cbo1 and press the "Search Button" to filter the record, it returns nothing meanwhile it has to return something.
    I came to realize that it was because the search code also takes into account the already set default value of Cbo2 and assume that it is a search criteria.

    Can anyone help me with this issue?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Code:
    if isNull(cbo1) or cbo1 = "Select Crop" then  sFlt1 = ""
    if isNull(cbo2) or cbo2 = "Select Country" then  sFlt2 = ""
    
    select case true
        case  sFlt1 = "" and sFlt2 = ""
             sWhere = "1=1"
    
        case  sFlt1 <> "" and sFlt2 <> ""
             sWhere = "Crop_Name Like '" & Cbo1 & "*' AND CountryName Like '" & Cbo2 & "*'"
    
        case sFlt1 = ""
             sWhere = "Crop_Name Like '" & Cbo1 & "*'"
    
        case sFlt2 = ""
             sWhere = "CountryName Like '" & Cbo2 & "*'"
    end select
     
    DoCmd.OpenForm "Frm_AppRateList", acNormal, , sWhere
    

  3. #3
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    Hi ranman256
    Thx for the quick reply.
    I added your code on the click event of my search button, but nothing happen. The default value does not show and the filtering option does not work as well.

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

Similar Threads

  1. Default Values/Placeholder Text
    By rezanaghibi in forum Reports
    Replies: 4
    Last Post: 06-18-2015, 02:36 PM
  2. textbox placeholder
    By cbrsix in forum Forms
    Replies: 0
    Last Post: 08-06-2014, 09:16 AM
  3. Simple Group By Query w a placeholder record?
    By murfeezlaw in forum Queries
    Replies: 2
    Last Post: 11-24-2012, 09:59 AM
  4. Displaying text in combobox
    By tylerg11 in forum Forms
    Replies: 9
    Last Post: 01-19-2012, 11:51 AM
  5. Replies: 1
    Last Post: 03-18-2009, 12:30 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