Results 1 to 15 of 15
  1. #1
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39

    Autofill Text Box from Cascading Combobox

    Hey Everyone,

    I have a cascading combo box setup that works completely fine. I now want to autofill several text boxes with information related to the second combo box.

    For example, in the first combo box the user is asked to select a facility. In the second combo box, it will list all the unit numbers of the inventory at that facility. As I said earlier, I was able to work this out.

    Now I am trying use Dlookup in the control source of the text boxes but I am not able to get anything to work.

    This is how I have set up my Dlookup:

    =DLookUp("[ItemIWantFilled]","TableName","[PrimaryIDinTable]=" & Forms![Formname]![2ndComboboxname.Column(X)]) and I just get an "#Error".

    Note I have several columns in the 2nd combo box and have also tried
    =comboboxname.Column(X) and nothing shows up.



    Please help!

    Thanks in advance

  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,521
    I'd go the second way:

    http://www.baldyweb.com/Autofill.htm

    If nothing is showing up, make sure the column count property of the combo is correct.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    hey i tried doing that..if I have one combo box this method works but when I have two combo boxes this method is not working. Here is what happens: When I go from Design View to Form View my text box will be populated as long as the first combo box is not updated. However when I change the first combo box, i.e. pick a different facility and then update the second combo box the textbox doesn't get filled.

    let me know if u need more clarification.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It should update whenever you change the value in the second combo. Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't like using DLookup(), unless I absolutely have to. I prefer to "push" the data into the text boxes.

    What you are attempting to do is called "Cascading Combo Boxes". When you change the first combo box, you need code in the after update event to requery the second combo box.

    There is an example at:
    http://www.rogersaccesslibrary.com/forum/topic389.html

    In the after update event code, I 'push' the data from the second combo box into the text boxes. (remember that the columns are zero based, so the second column is column(1).)

  6. #6
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    unfortunately, no because all the data is linked to a different server and i wont be able to release all this information anyways.

  7. #7
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    Quote Originally Posted by ssanfu View Post
    I don't like using DLookup(), unless I absolutely have to. I prefer to "push" the data into the text boxes.

    What you are attempting to do is called "Cascading Combo Boxes". When you change the first combo box, you need code in the after update event to requery the second combo box.

    There is an example at:
    http://www.rogersaccesslibrary.com/forum/topic389.html

    In the after update event code, I 'push' the data from the second combo box into the text boxes. (remember that the columns are zero based, so the second column is column(1).)
    hey, I already have the cascading combo boxes working fine...how exactly do you push the data? is it by using:

    Me.textboxname = Me.combobox.Column(X)? I tried doing that as well and once again nothing happening.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    hey, I already have the cascading combo boxes working fine...
    You are missing the VBA that re-queries the combo boxes.

    how exactly do you push the data? is it by using:

    Me.textboxname = Me.combobox.Column(X)? I tried doing that as well and once again nothing happening.
    Yes, but you have to have it in the after update event of the second combo box.

    Attached is a A2K mdb that I did a long time ago (don't laugh too hard). But it has multiple cascading combo boxes with data being pushed into text boxes. One button opens a form with combo boxes and another one does the same thing as the first form, but uses list boxes. If I had it to do over again, I would use a different structure for the tables, but it will work as an example. (good or bad..... )

  9. #9
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    okay, i will try looking at this and see what i can do. thankx.. i will try to post my results tomorrow..thanks for all your help guys!

  10. #10
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    hey ssanfu, I looked at your database but I have a different set up than you and thus your method won't work for me. I am attaching a sample database that looks similar to what I will have. please try to have a look at it and show me a way in which the textbox can be filled.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your code to populate the second combo:

    Code:
    Private Sub Combo0_AfterUpdate()
    On Error Resume Next
        Combo2.RowSource = "Select AllData.VehicleID " & _
            "FROM AllData " & _
            "WHERE AllData.Facility = '" & Combo0.Value & "' " & _
            "ORDER BY AllData.VehicleID;"
    End Sub
    Where is Year in that?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    haha thanks...now i'm a newbie in VBA so can u guide me as to which argument i should be using so that my Year, Make fields are added to the second combo box..u don't have to give me the whole argument but atleast something that i can start with.

    would it be similar to the Where clause??

    Thanks again.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It would look like the SQL that the combo starts with:

    Combo2.RowSource = "SELECT AllData.VehicleID, AllData.Facility, AllData.Year, AllData.Cost, AllData.Make " & _
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    thanks a lot! ur a life saver...

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. cascading combobox and validation rule violation
    By AndycompanyZ in forum Forms
    Replies: 7
    Last Post: 06-22-2011, 12:13 PM
  2. Cascading combo box updating text box?
    By RemonKoybito in forum Forms
    Replies: 1
    Last Post: 06-16-2011, 10:51 AM
  3. Replies: 1
    Last Post: 02-04-2011, 04:58 AM
  4. ComboBox Autofill
    By t_dot in forum Forms
    Replies: 2
    Last Post: 08-19-2010, 06:18 AM
  5. Replies: 1
    Last Post: 03-18-2009, 12:30 AM

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