Results 1 to 5 of 5
  1. #1
    lilanngel is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    7

    Select field you want to search, select value, then Search

    Hi,

    The goal of my project is to create 2 combo boxes and one "button" that enables the user to search my database.

    The first combo box (called FieldCBO) lists the field names: Eg. "Last Name, First Name, Address" fields from the "CONTACTS" table.

    The second combo box (called ValueCBO) is bounded to the first combo box so that if you select the "Last Name" field, everyone's last name will show up (e.g. Smith, Doe, etc), if you select the "First Name" field, everyone's first names will show up (e.g. John, Jane, etc)...

    Unfortunately, I can't get this second combo box. I believe something is wrong with my "Row Source: SELECT Forms![Search Form]!FieldCBO FROM CONTACTS" because an error message stating "The Access database engine does not recognize 'Forms![Search Form]!FieldCBO' as a valid field name or expression



    What should I put in place of "Forms![Search Form]!FieldCBO"?

    Thank you for your help!!

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    I think you need something like this:
    SELECT Contacts.LastName FROM CONTACTS WHERE Contacts.LastName=[Forms![Search Form]!FieldCBO;

    NB: Replace LastName with the correct field name in your database.

    You will also need to requery the 1st control after each selection.

  3. #3
    lilanngel is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    7
    Quote Originally Posted by SoftwareMatters View Post
    I think you need something like this:
    SELECT Contacts.LastName FROM CONTACTS WHERE Contacts.LastName=[Forms![Search Form]!FieldCBO;

    NB: Replace LastName with the correct field name in your database.

    You will also need to requery the 1st control after each selection.
    Thanks, JD!

    The FieldCBO is actually a list of "fields" in the CONTACTS table... so I don't think I want to set the Contacts.LastName to equal it, right? (Sorry if I'm incorrect).

    I want to base the value list in the second combo box on the field selection from the first combo box.

    E.g. if the person selects Last Name from FieldCBO, the ValueCBO automatically populates with everyone's last name

    if the person selects First Name from FieldCBO, everyone's first names will show up.

    But I'm not sure how to do this..

  4. #4
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Sorry I misunderstood but now I get it!

    This should be easy to achieve using code.

    You could set the Rowsource of your 2nd combo to contain all the required fields and then on the AfterUpdate of the first combo set the ColumnWidths to show the appropriate field. Below is an example of waht I mean:

    Code:
     
    Private Sub FieldCBO_AfterUpdate()
    Me!ValueCBO = Null
    Select Case Me!FieldCBO
        Case 1
            Me!ValueCBO.ColumnWidths = "6 cm;0;0"
        Case 2
            Me!ValueCBO.ColumnWidths = "0;6 cm;0"
        Case 3
            Me!ValueCBO.ColumnWidths = "0;0;6 cm"
    End Select
    Me!ValueCBO.Requery
    End Sub
    This is just an example but hopefully you get the idea.

    Another method would be to set the rowsource depending on the selection.

  5. #5
    haquocquan is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    3
    I think you can not do it. Because: at a time, combo gets value in one field.
    If you add options on form, you will do it.

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

Similar Threads

  1. 2 multi select list boxes on one search form
    By woodey2002 in forum Forms
    Replies: 2
    Last Post: 11-05-2010, 12:44 PM
  2. Replies: 2
    Last Post: 08-31-2010, 08:57 PM
  3. Replies: 3
    Last Post: 03-22-2010, 04:30 PM
  4. Field Select
    By RaptureReady in forum Forms
    Replies: 1
    Last Post: 01-28-2010, 08:29 PM
  5. Replies: 1
    Last Post: 02-25-2009, 07:29 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