Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating a combo box after updating its table source 1

Status
Not open for further replies.

vanleurth

Programmer
Sep 1, 2001
156
0
0
US
Hi happy programmers,

I have a combo box and a button right next to each other. The button opens a table (form) that is the rowsource of the combo box. I would like to update the combo box once I have added another record to the table source.

Here is an example;

Let's say I want to define or delete an entry from my combo box that shows all departments in my company.
1. Click on the button that brings the form for departments
2. Add or delete the department in the table
Here is what I don't know how to resolve.
3. Once I close the form of departments the combo box requeries the table and choose the first entry as default, so the first entry is already chosen.

I'm using Onfocus event to requery the combo box everytime it gets focus(of course) whether the table has been updated or not. I still can't figure out how to choose the first entry.

If anyone knows of a better or more elegant way to do this please let me know,

Thank you in advance,

V.
 
Vanleurth, do you mean you want to repopulate the combobox with the table's recordset each time the combobox recieves the focus? Also, what do you mean you can't figure out how to choose the first entry? Do you have any code you could show?
 
Hi Marina,

Sorry for the week later reply. I have been ery busy. Thank you for your interest in helping out. Here is the code for the button.

Private Sub btn_type_Click()

' Open the training type form
DoCmd.OpenForm "frm training type", acNormal

End Sub

This calls the form that manages the table entries for training type. Once I have made modifications I would like to close to form and update a combo box that has the training type table attach to the rowsource. In that way, the combo box shows all latest entries.

So, here is what I come up with;

Private Sub Type_GotFocus()
' Requery this combo box
Me.Type.Requery
End Sub

I don't think this is very elegant and also it overload the computer with unnecesary work since sometimes I just want to tab through this field and not necessarily change its content by accesing the type form.

Please, let me know if this is good enough. Sometimes, it is difficult for me to explain what I'm trying to do.

Thanks in advance,

V.
 
Vanleurth,

Sorry for the delayed response. I live in Florida so I was dealing with a hurricane this past weekend.

What you may want to do is place the requery code in the btn_type_Click() section rather than the Type_GotFocus()section to prevent the "overload" for your computer. The trick to doing this is to make the rowsource form modal when it is opened by the DoCmd.OpenForm code:

Private Sub btn_type_Click()

' Open the training type form
DoCmd.OpenForm "frm training type", acNormal, , , , acDialog
' Requery this combo box
Me.Type.Requery

End Sub

This way the recordsource form will need to be closed before the requery portion of the code is run, and you will get the most up to date recordsource. You can then remove the requery code from the GotFocus event of the combo box. Hope this helps!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top