Update combo box on form

J

Jef

Hello, I am a newbie: I have several tables that consist
of PartID, PartDesc; LocationID, LocationDesc;
WarehouseID, WarehouseDesc. These small tables link up to
a main table that holds other informaton.

While working with the main table, these fields are shown
by a combo box and I can select the needed values. If the
value doesn't exist in the combo box I have a command
button to open the needed form, I can add the needed item
and then close that form.

The question is: How do I get the Combo Box list updated
without closing the form and re-opening it.

Any and all help would be greatly appreciated.

Thanks in advance
 
K

Ken Snell

Your code in the OnClick event for the command button (the one that opens
the "add" form) needs one additional step after the DoCmd.OpenForm step:

Me.cboBoxName.Requery

where cboBoxName is the name of the combo box on the first form.

I'm assuming that you're opening the second form in dialog mode.
 
J

Jeff

Ken, Thanks for the quick reply! It did help somewhat
but, I still have a problem. If I click the command
button to open the 2nd form then add the item that I want
and then exit the 2nd form back to the 1st form the item
still doesn't show up in the combo-box list. However, if
I click the command button to open the 2nd form a 2nd time
then exit back to the 1st form the item now shows up in
the combo-box list. Any ideas?

I'm not sure what you mean by: "I'm assuming that you're
opening the second form in dialog mode."? Where can I
look for this setting?

Thanks,
Jeff
 
K

Ken Snell

Post the code that is running on the OnClick event of the command button
(the one that opens the second form). What code runs in the second form
(either after you enter the new information or you click a command button or
something)?

Let's see what you're actually running and then we'll get into details.
 
J

Jeff

Ken, here is the code that is running for the command
button to open the 2nd form:

Private Sub Command36_Click()
On Error GoTo Err_Command36_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "AdministredTable"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me.AdministredID.Requery

Exit_Command36_Click:
Exit Sub

Err_Command36_Click:
MsgBox Err.Description
Resume Exit_Command36_Click

End Sub

On the 2nd form I only have one command button at this
time. That command button has an action to close the
form. Should I have something else?

I have to use the 'wizards' to help build my forms and
reports as I don't know how to write the code. I can read
the code and understand some of it. I used to program in
COBOL on HP systems.

Thanks for your time and help,
Jeff
 
K

Ken Snell

OK easy fix...

Change this line of code:
DoCmd.OpenForm stDocName, , , stLinkCriteria
to this:
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog

This will cause your code to pause until the second form is either closed or
hidden. Assuming that you're closing the second form, then the code should
properly requery the combo box after the second form has added the value (in
your code, the requery was running before you entered any information into
the second form, let alone saved it to the table) and the combo box then
will show the added value in its dropdown list.
 
J

Jeff

Ken, THANK YOU!....You've helped me out so much. Thanks
for your time and patients with this newbie. Everything
is working just the way that I want at this point.

Thanks agan and take care!
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top