Results 1 to 8 of 8
  1. #1
    jbeets is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2020
    Posts
    94

    Second combobox value populated from one of 2 tables based on first combobox value

    Hello!

    I have a form with 2 comboboxs . cbo_JobType has 2 options "Hourly" or "PieceWork".
    I have two tables "tbl_HourlyJobs" and "tbl_PieceWork". The hourly jobs have individual pay rates based on the employee. The Piecework jobs are all paid the same but there are about 40 of them.

    What I am hoping to do is, based on what option is selected in cbo_Jobtype I would like the combobox to populate from the correct table.



    I think I need to use VBA and possibly a Select Case statement but I am not sure how to write it.

    Any suggestions on how I can make this work?

    Thank you so much for any help you can provide!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    This is known as cascading or dependent combobox (or listbox) and is a very common topic. Yes, VBA will be involved.
    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
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just curious - why do you have 2 tables? Are the table structures that different?

  4. #4
    jbeets is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2020
    Posts
    94
    Quote Originally Posted by ssanfu View Post
    Just curious - why do you have 2 tables? Are the table structures that different?
    Well, I didn't know how else to do it basically. The first table lists the hourly job rates for each employee. There are 13 different jobs and each employee may have a different payrate for each job. The second table has the jobs that are paid by the pieces completed. Each employee makes the same rate for these jobs but there are about 40 different jobs and 40 employees.

    Also, I understand dependent combo boxes but I have never tried to base it off of two tables feeding into the same drop down. Since I couldn't figure that out I just did two different comboboxs and only the one that relates to the main combo box will populate.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    VBA would just change the combobox RowSource property.
    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.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Without knowing the table structures, I would have 1 table with an additional field for JobType - "Hourly" or "PieceWork".
    Then it is easier to select the fields you want to have in combo box 2.


    As far as VBA, there are several options.
    You could have a couple of constants that have the SQL for each table and change the row source in the combo box
    Code:
    If Me.cboJobType = "Hourly" Then
      sSQL = "Select Field1, Field2 From tbl_HourlyJobs"
    Else
      sSQL = "Select Field1, Field2 From tbl_PieceWork"
    End If
    
    Me.cboBox2.SQL = sSQL

    Case to post your table structures?
    Or you could build the SQL string using VBA.

  7. #7
    jbeets is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2020
    Posts
    94
    Thank you so much, this was much easier than I was making it out in my head. Thank you for walking me through how this would work!

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy to help....

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

Similar Threads

  1. Replies: 11
    Last Post: 11-25-2013, 01:46 PM
  2. Replies: 9
    Last Post: 01-17-2013, 09:08 PM
  3. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  4. Replies: 5
    Last Post: 07-29-2011, 03:07 PM
  5. Replies: 0
    Last Post: 08-24-2010, 06:38 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