Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    combo box question (XP,2000)

    I have a table and two of the fields (country, countrycode) need to be filled with values from a combo box. the combo box is based on a query. I am able to fill one fields (country) which is a combo box control on the form but am unable to fill the seond one which is a text box control. It seems to me that since both of the values (country & country code) are in my query and displayed in the combo box, that i should be able to fill both of those fields. I have tried doing an afterupdate event for the combo box using the following code but it does not work.

    Private Sub Combo87_AfterUpdate()
    Me!NationCode = "=[combo87].Column(1)"
    End Sub

    What do I have wrong?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: combo box question (XP,2000)

    You don't need to use code for this. Just set the Control Source of NationCode to

    =[combo87].Column(1)

  3. #3
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combo box question (XP,2000)

    Thanks, Hans. That does work insofar as displaying the correct data on the form but it fails to populate the field in the table.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: combo box question (XP,2000)

    Is the text box bound to a field in the table?

  5. #5
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combo box question (XP,2000)

    Yes - or, at least it is now. I originally had it bound to a field then changed the control source as Hans suggested. Since that did not update the table field, I reset the control source to the field and am using an after_update event to assign the value to the text box and, since it is bound to the field, it updates the table.

    I think I have it working correctly now although I am not confident this is the most elegant (efficient) way to do it.

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: combo box question (XP,2000)

    What puzzles me is why you want to keep this value in the table when it is available in the table referenced by the combo box.
    Surely if you need to get this field for any reason you just join the reference table by country.

  7. #7
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combo box question (XP,2000)

    I thought about that and realize that would be better but what I am doing now is within my knowledge limitations and it works. It will get better over time as I learn more about Access and database design. Right now, however, my first priority is to have a working, even if not normalized, database application.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: combo box question (XP,2000)

    That's fair enough, there's a lot to learn in Access so learning at your own pace obviously makes sense.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: combo box question (XP,2000)

    Learning good database design is an important part of becoming an Access developer.
    But if you really want to store both values in your table, this should work:

    Private Sub Combo87_AfterUpdate()
    Me!NationCode = [combo87].Column(1)
    End Sub

    The quotes and extra = you included in your code tried to set the value of the field to an expression (a formula) instead of to the correct value.

Posting Permissions

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