Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2011
    Posts
    11

    Unanswered: Using ComboBox to automatically fill in textbox and combobox on form - Access 2003

    Happy Monday!
    Here's my situation:

    When the user selects a state from combobox cboLookState on the form (frmEntry), this would fill in an unbound combobox (cboStateConsentNeeded) with the state form needed for that state and an unbound textbox (txtStateRegs) with the state regulations for that state. The first part works as planned: When selecting CA from the state list, state form N201CA loads in the cboStateConsentNeeded. The second part does not work. No errors, no information fills, just doesn't "do" anything. I have tried it as a combobox as well as a textbox; both as text; both as combo; comment out the first part of the event to have the second part start first - nothing works. I've tried this code in both the AfterUpdate event and the Change event.

    Private Sub cboLookState_AfterUpdate()
    Me.cboStateConsentNeeded = Me.cboLookState.Column(2)
    Me.txtStateRegs = Me.cboLookState.Column(4)
    End Sub

    Apparently, I'm missing something. Does the length of text make a difference? My txtStateRegs is formatted to 255 words; the cboStateConsentNeeded is formatted to 50. I'm using Access 2003. And I accept any help offered!

    Thanks
    BattyOwl

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14

    Happy Monday too!

    The code seems to be correct. I'm not sure that's applicable to your case but did you consider that the leftmost (first) column of a combobox (or listbox) is Column(0)?
    Last edited by Sinndho; 02-27-12 at 18:24.
    Have a nice day!

  3. #3
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Also make sure the Column Count property of the combo is appropriate to the number of fields in the row source (in your case, at least 5).
    Paul

  4. #4
    Join Date
    Dec 2011
    Posts
    11
    Yes, considered Column 0, but it doesn't change the end result. I did change the column count to 5 (was at 4) just to play devil's advocate. No change.

    I feel like I'm looking for a golden goose here...

    Thanks for the suggestions!

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Can you post the db here, or a representative sample?
    Paul

  6. #6
    Join Date
    Dec 2011
    Posts
    11
    I'm unable to share the database, sorry!

  7. #7
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Nor a representative sample? What is the row source of the combo?
    Paul

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Could you add the following modifications to your code for testing purposes:
    Code:
    Private Sub cboLookState_AfterUpdate()
    
    '    Me.cboStateConsentNeeded = Me.cboLookState.Column(2)
    '    Me.txtStateRegs = Me.cboLookState.Column(4)
    
        Dim i As Long
    
        For i = 0 to 4
            Debug.Print i, Me.cboLookState.Column(i)
        next i
    
    End Sub
    Then open the form, change the selected value in the combo, switch the form to Design mode, open the VBA Editor (Alt+F11) open the Immediate Window (Ctrl+G) and see what you have there?

    If nothing was printed in the Immediate window, check that the code is effectively bound the the AfterUpdate event of the combo: open the Property window (Alt+Enter), select the Event tab, then the After Update line: it should contain [Event Procedure]. If it does not, click on the square button with 3 dots on the right of the line to open the VBA Editor and create the association.
    Have a nice day!

  9. #9
    Join Date
    Dec 2011
    Posts
    11
    Sinndho, that did it! Somehow my column 4 became column 3 - only saw that in the Immediate window. Switched it to 3 in code and all is well with the world!

    Thank you all for your help!

    I'm sure I'll be 'seeing' you soon...

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •