Results 1 to 7 of 7
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181

    Cascading combo box - Need VBA help for auto-update of dependent field

    On a form in one of my databases, I have two combo-boxes, and one feeds the other via cascading information. I picked up the tip here: http://fontstuff.com/access/acctut10.htm

    The two combo boxes are Supplier Name and Supplier Number.



    I need Supplier Name to update Supplier Number automatically. If you choose one Supplier Name, then the Supplier Number cascaded into the combo-box, and then change Supplier Name, Supplier Number does not auto-update, meaning it is now mismatched. This is a potential risk for users entering wrong data into the tables. I am wondering if there is a quick Form Properties or VBA fix for this issue. Any ideas?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    That sounds more like:

    http://www.baldyweb.com/Autofill.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    I agree with Paul; Cascading Comboboxes are intended to be used when a given selection, in the first Combobox, will generate multiple, possible selections, in the second Combobox.

    If the original selection is only going to generate a single, possible item, using a single Combobox, in the manner that his code demonstrates, is the way to go.

    FYI, the problem with the code you were given at the above site

    Code:
    Private Sub cboCountry_AfterUpdate()
       On Error Resume Next
       cboCity.RowSource = "Select tblAll.City " & _
                "FROM tblAll " & _
                "WHERE tblAll.Country = '" & cboCountry.Value & "' " & _
                "ORDER BY tblAll.City;"
    End Sub

    is that it doesn’t reset the second Combobox so that a previous selection, if any, doesn't remain showing. Adding a single line
    Code:
    Private Sub cboCountry_AfterUpdate()
       On Error Resume Next
       cboCity.RowSource = "Select tblAll.City " & _
                "FROM tblAll " & _
                "WHERE tblAll.Country = '" & cboCountry.Value & "' " & _
                "ORDER BY tblAll.City;"
       cboCities = ""
    End Sub
    would have taken care of that, and is usually standard. BTW, that site usually gives excellent advice/examples, and I'm sure that this was simply an oversight on their part!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181
    Thanks for both of your replies. I'm still not able to figure out how to make what I need. Attached is my best attempt. Any ideas?

    Autofill.mdb

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    You've got your two Comboboxes mixed up! The one labeled, on your Form, as Supplier Name, is actually the Supplier Number Combobox, and vice versa!

    Your actual Supplier Number Combobox has a RowSource of

    SELECT tblSUPPLIER.Supplier_Name FROM tblSUPPLIER;

    Don't know that it makes any difference, but the line

    cmboSupplierNumber = " "

    should be

    cmboSupplierNumber = ""

    setting the cmboSupplierNumber to a Zero-Length String.

    All that said, as both Paul and I have indicated, you're going about this wrong! Even if you get this working, you'll have a second Combobox with a single item to be selected, which will have to be selected; it will not automatically show up in the Combobox, which makes no sense!

    Follow the link to Paul's site and set up a single Combobox, with both the Supplier Name and Supplier Number in the RowSource, then assign the Supplier Number to a Textbox on your Form, as his demo shows.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181
    Thanks for your help! I finally got this solved. Attached is the solution for reference.

    Autofill.mdb

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Glad you got it working, and glad to see that you also replaced you second Combobox with a simple Textbox, which is all that is needed, here!

    Good luck with your project!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Combo Box auto fill and update table
    By memmons in forum Access
    Replies: 4
    Last Post: 09-27-2012, 11:58 AM
  2. auto fill text box from dependent combo box
    By tommyried in forum Access
    Replies: 6
    Last Post: 06-17-2012, 03:55 PM
  3. Replies: 7
    Last Post: 12-29-2011, 10:13 AM
  4. Replies: 4
    Last Post: 02-08-2011, 08:43 AM
  5. Replies: 1
    Last Post: 03-08-2009, 01:50 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