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

Status
Not open for further replies.

FoxProProgrammer

Programmer
Apr 26, 2002
967
0
0
US
I'm sure that this is a simple issue, but I'm new to Access and couldn't find an answer in the Help.

I am developing a form that tracks the calibration history of equipment. The form displays three fields from the "calibration" table in a three column combo box (last cal date, next cal date, and cal report number). The calibration table (child) is related to the "serial number" table (parent) through a foreign key. The form has a button that the user presses to add new calibration data to the database. When the user presses the "Add" button, a new form is presented where the user enters the last cal date, next cal date, and cal report number. The user then presses the "Save" button on the Add form, the data is saved, and the Add form closes.

At this point, the combo box needs to be updated to include the new record that was entered. I can't figure out a way to get the combo box to execute the query again without closing the form and reopening it. That is not a good solution. I tried setting the RowSource to the query string in the Form "On Got Focus" event, but that doesn't work. In fact, this procedure doesn't even run when the focus changes from the Add form to the form with the combo box. So, I have two questions:

1. Why isn't my On Got Focus procedure running when the Add form closes and the form with the combo box gets the focus?

2. How do I force the combo box to do the query without closing and opening the form? If I could get the On Got Focus procedure to run, my solution might work...but I'm not sure if resetting the RowSource will cause the query to execute.

Thanks for your assistance.

dz
 
Here are the answers:

1. "GotFocus" of the form works quite differently from that of a control. What you should use instead is "Activate" and "Deactivate" properties of the form. But, you don't need them to update your combo box if you do 2 below.

2. You can simply use the Requery like

Mycombobox.Requery

This will refresh the contents of the combobox. If you use the Add form, open that form with "acDialog" qualifier and add the requery command like:

DoCmd.Openform "frmAddCal",,,,, acDialog
Mycombobox.Requery

The acDialog qualifier will suspend the program on the main form until you close the Add form. Then, the requery command will refresh the combobox after the Add form is closed.

Cheers


 
Thanks so much for your reply. Your suggestion works like a charm!

The acDialog qualifier raises a question, however. What is the difference between acDialog and turning the Modal and Popup properties on?

You seem quite knowledable on Access and nobody responded to a question that I had earlier. It is thread181-263006 with subject "Adding records to a table through a form". If you have a chance to look at that issue, I would greatly appreciate it. It isn't a big deal because it works like I coded it, but I am curious if there is a better way to do this.

Thanks again for your help,

dz
 
If u make form open as acdilaog
the control waits until form is closed
and then moves on to next statement

If the form is modal and popup u will have no problems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top