Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56

    Update Value in Combo Box

    Hello,



    I want to be able to update value in text box based on the value in a combo box. This would be in a Access form.

    For example, I have the following values in a table.

    Name Number
    Johnson 1234
    Curtis 5678
    Jones 2468

    So, I did the following....

    The Row Source of the combo box needs to include both columns (fields).

    =[YourComboBox].Column(1)

    This worked (when entering data in name field, number field updates in the form) but now i am finding when i add data thru the form the number fields are not updating in the table. All the other fields in the form are updating.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Use the AfterUpdate event of the ComboBox to update the TextBox that is bound to the field you want. Me.txtControl = Me.[YourComboBox].Column(1)

  3. #3
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56
    Sorry for my ignorance but what does "Me" mean?

    "Me.txtControl = Me.[YourComboBox].Column(1)" mean?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It is a reference to the Form where the control is located. When you use that syntax, intellisense is activated when you type the first period and the available choices are displayed for you to choose from.

  5. #5
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56
    So do I input the code below in the after update event row? Do I add to open code builder screen (VB)
    Me.txtControl = Me.[YourComboBox].Column(1)

    What does txtControl refer to? is that the field i am wanting to update based on the the combo box?

    Thanks

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    On the AfterUpdate event row on the property sheet for the ComboBox, press the "..." button and select CODE. Then you put the code before the End Sub line. Me.txtControl refers to the control that displays the value you are trying to save. You need to remove what you have as the ControlSource:
    (=[YourComboBox].Column(1)) and instead make it point to the field in which you want to save the value. The name of each control is on the "Other" tabe of the respective property sheet.

  7. #7
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56
    This is still not working. The .txt box is not updating the table. I updated the code to the following.

    Combo box - ApprovingOfficial (control source)

    After Update
    Private Sub ApprovingOfficial_AfterUpdate()
    Me.AO_Credit_card = Me.ApprovingOfficial.Column(2)
    End Sub

    Text box - AO_Credit_card
    Control source - AO_CARD

    When I insert name in ApprovingOfficial, it does update txt box but still does not update field in table.

    What am I missing?

    Thanks

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It looks right to me. The field in the table that is *not* getting changed is named AO_CARD, right?

  9. #9
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56
    No, actually I want the AO_CARD field to change. The value should be updated based on ApprovingOfficial.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by RuralGuy View Post
    The field in the table that is *not* getting changed is named AO_CARD, right?
    It looks like the answer to my question is yes when you answered "No, actually I want..."

  11. #11
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56
    You are correct. The question is why isn't AO_CARD being updated in the table?

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Can you type directly into this TextBox and have the change saved?

  13. #13
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56
    Yes. It does save to the table.

    Thanks

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The code in the AfterUpdate event of the cbo will *not* Dirty the record on its own. Use the cbo and then change another bound control to dirty the record and see if the cbo change is then saved.

  15. #15
    j2curtis64 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    56
    "The code in the AfterUpdate event of the cbo will *not* Dirty the record on its own. Use the cbo and then change another bound control to dirty the record and see if the cbo change is then saved."

    I am sorry but you lost me. What do you mean by dirty the record?

    Are you saying i need to change this?

    Private Sub ApprovingOfficial_AfterUpdate()
    Me.AO_Credit_card = Me.ApprovingOfficial.Column(2)
    End Sub

    Thanks


Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combo Box Update Form
    By k9drh in forum Forms
    Replies: 3
    Last Post: 05-04-2011, 04:34 AM
  2. Combo box with query and update
    By traction in forum Access
    Replies: 0
    Last Post: 11-24-2010, 02:38 PM
  3. Update form using combo box
    By rosh41 in forum Forms
    Replies: 1
    Last Post: 07-01-2010, 04:57 PM
  4. Use combo box to update other fields
    By Shep in forum Access
    Replies: 7
    Last Post: 07-23-2009, 03:11 PM
  5. After Update for a second Combo box
    By nywi6100 in forum Forms
    Replies: 0
    Last Post: 10-23-2006, 03:07 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