Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2004
    Posts
    10

    Unanswered: Stupid Newbie: How do I populate a combobox with values from a table?

    Hey guys,

    I'm developing a DB with Access 2000 and VBA, and was hoping you could help me. Right now, the problem I'm stuck on is this: I've got a group of 3 option buttons on one form. The option buttons correspond to fields on a table I've made.

    Anyways, when the first form exits, I open a new form, which contains a combobox. I would like to have that combobox populated with the corresponding data from my table. For example, if I had option 1 selected on the first form, I'd like the second form's combobox to contain all the data in field 1 from my table.

    It doesn't sound that complicated to me, but I can't figure it out for the life of me.

    Thanks.

  2. #2
    Join Date
    Sep 2004
    Posts
    161
    You can use the SourceControl Property or the recordsource property of your combo.

  3. #3
    Join Date
    Sep 2004
    Posts
    8
    the combobox has a property called boundcolumn. It is a value that corresponds to the column displayed in the combo box eg 1 for the first column, 2 for the second, etc. i would set this to the corresponding number when you open the form for example in the form open code i would put something like

    " Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "formname" ' Open new table
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    if option1.value = true then form_formname.combobox.boundcolumn = 1
    if option2.value = true then form_formname.combobox.boundcolumn = 2
    if option3.value = true then form_formname.combobox.boundcolumn = 3

    docmd.close ' close the first form "

    where formname is the new form youve opened and combobox is the name of the combobox you wish to populate. Is that helpful, if not let me know ill try and help more

  4. #4
    Join Date
    Sep 2004
    Posts
    10
    So, I would put that code in the form open code for the form I've got the combobox on? Why would I call docmd.openform from there, then?

    Also, whenever I put code (any code at all) in form_open, I get "The OpenForm action was cancelled", and nothing happens.

    Thanks

  5. #5
    Join Date
    Sep 2004
    Posts
    161
    In the same way and to complete my response :
    if option1.value = true then form_formname.combobox.sourcecontrol = Field1
    if option2.value = true then form_formname.combobox.sourcecontrol= Field2
    .....
    or with the rowsource use a query selecting Field1 or Field2 or ....

  6. #6
    Join Date
    Sep 2004
    Posts
    10
    > or with the rowsource use a query selecting Field1 or Field2 or ....

    This is what I was trying to do, and putting it in the form_load method. Problem is, form_load doesn't get called (is it only when it is first called, or what?), and like I said, whenever I put any code in form_open, the program chokes.

  7. #7
    Join Date
    Sep 2004
    Posts
    161
    Yes the load event is called only when you're load the form.
    You can put your code on the change event of your option and requery your combo

  8. #8
    Join Date
    Sep 2004
    Posts
    10
    So, put the code in the change even of the option group on the first form, and then requery the combo box in the second form? Will this work even if the second form has not been opened, yet?

  9. #9
    Join Date
    Sep 2004
    Posts
    161
    You can change the query in change event of your option group and make the requery in the activate event of the second form, i think

  10. #10
    Join Date
    Sep 2004
    Posts
    10
    Heh, ok. Now I get an out of memory error whenever I change options.

    Man, I miss programming in C

  11. #11
    Join Date
    Sep 2004
    Posts
    10
    I guess it's probably worth noting I'm not actually out of memory when that error shows up.

Posting Permissions

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