Requering combobox after change to underlying table

D

Dave the Wave

Form A (based on a main table) has a combo box filled with records
from a different table. The combo box's dblClick event opens up a form
(PopUp=Yes, Mod=Yes) listing all the records for the underlying
table.

I've got that part working, but I can't figure out how to update the
combo box record list on the main form. The changes to the underlying
table are not refelected until the form is closed and reopened.

I've tried using the main form's gotFocus event, but it doesn't
trigger when the underlying table's form get's closed.

Thanks for any help
 
B

Barry Gilbert

If the second form is opened as a popup, the code that opens it will
continue to execute after the popup form is closed. That's where you
can call the cmobo's requery. Something like this:

DoCmd.OpenForm "MyForm", acWindowMode=acDialog
' Here's where the form is open. When it closes, it will execute the
next statement.
Me.MyCombo.Requery

HTH,
Barry
 
D

Dave the Wave

If the second form is opened as a popup, the code that opens it will
continue to execute after the popup form is closed. That's where you
can call the cmobo's requery. Something like this:

DoCmd.OpenForm "MyForm", acWindowMode=acDialog
' Here's where the form is open. When it closes, it will execute the
next statement.
Me.MyCombo.Requery

HTH,
Barry

Barry:
Thanks, but that doesn't seem to work. Here's the code I used:

Private Sub cbxGroup_DblClick(Cancel As Integer)
On Error Resume Next
DoCmd.OpenForm "frmGroup", , , , , acDialog
Me.Requery
End Sub
 
D

Dave the Wave

Dave,

Try:

Me!ComboName.Requery

HTh,
Josh
Thanks Josh, the problem however is where do I put the code that it
triggers when the main form gets the focus (becuase the pop up form
has been closed). Putting the code in the main form's GotFocus event
doesn't seem to work.
 
J

Joshua A. Booker

Because you're using a modal pop-up the code in the main form will pause
until the pop-up is closed. So you can put it directly after the code that
opens the pop-up.

HTH,
Josh
 
J

Joshua A. Booker

Me.Requery will requery the main form not the combo.
Me.ComboName.Requery will requery the combo list.

HTH,
Josh
 
D

Dave the Wave

If the second form is opened as a popup, the code that opens it will
continue to execute after the popup form is closed. That's where you
can call the cmobo's requery. Something like this:

DoCmd.OpenForm "MyForm", acWindowMode=acDialog
' Here's where the form is open. When it closes, it will execute the
next statement.
Me.MyCombo.Requery

HTH,
Barry

I figured out a way. I added the controls name to the OpenForm command
as the OpenArgs string. When closing the form I use the OpenArgs
string to requery the combo box. It works??? Here is the code

Main Form:
Private Sub cbxGroup_DblClick(Cancel As Integer)
On Error Resume Next
DoCmd.OpenForm "frmGroup", , , , , acDialog, "cbxGroup"
Me.Requery
End Sub


PopUp Form:
Private Sub cmbExit_Click()
On Error GoTo Err_cmbExit_Click

Forms("frmMainData").Controls(Me.OpenArgs).Requery
DoCmd.Close

Exit_cmbExit_Click:
Exit Sub

Err_cmbExit_Click:
MsgBox Err.Description
Resume Exit_cmbExit_Click

End Sub
 
D

Dave the Wave

Dave,

Try:

Me!ComboName.Requery

HTh,
Josh
I figured out a way. I added the controls name to the OpenForm command
as the OpenArgs string. When closing the form I use the OpenArgs
string to requery the combo box. It works??? Here is the code

Main Form:
Private Sub cbxGroup_DblClick(Cancel As Integer)
On Error Resume Next
DoCmd.OpenForm "frmGroup", , , , , acDialog, "cbxGroup"
Me.Requery
End Sub


PopUp Form:
Private Sub cmbExit_Click()
On Error GoTo Err_cmbExit_Click

Forms("frmMainData").Controls(Me.OpenArgs).Requery
DoCmd.Close

Exit_cmbExit_Click:
Exit Sub

Err_cmbExit_Click:
MsgBox Err.Description
Resume Exit_cmbExit_Click

End Sub
 
D

Dave the Wave

Me.Requery will requery the main form not the combo.
Me.ComboName.Requery will requery the combo list.

HTH,
Josh
Right you are. I missed that. I will try that method again as I have
to implement this procedure on a number of popup forms.

Thanks much for you help!
 
D

Douglas J. Steele

What are you trying to use?

You should be able to do something like Forms!MyForm!MyCombo.Requery in the
close of the other form.
 

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