Update value in a combo box

  • Thread starter Thread starter Ivor Williams
  • Start date Start date
I

Ivor Williams

I have a form with a combo box. Typically, an item number is entered in the
combo box and the item description is displayed. Ocassionally, only the item
name is known, so I've created a second form sorted by name which also
displays the item number. I use a command button to open the second form
from the first form. When I choose the appropriate item in the second form
by name, I would like to have the combo box in the first form updated and
the second form close. How can I do this?

Ivor
 
Hi Ivor,

You can either put code in the first form which pulls the value from the
second form before it closes or put the code in the second form to 'push'
the value to the first form (again) before closing.

Often I will go with the first method - first I open the second form in
'dialog' mode using the acDialog option of the WindowMode paremeter of
docmd.Openform. When used, the code in the first form will pause until the
second form (the one being opened) is either hidden or closed. With this in
mind, on the second form put an 'OK' button which the user clicks to
indicate that a selection has been made. The code behind the OK button
should hide the form (rather than close it). Once the second form is hidden,
the code in original form will resume and can use the value in the control
on the now hidden form to set the value of the combo. Then the second form
is closed by the first form. Here's some sample code:

Code on first Form:

Private Sub Command19_Click()
DoCmd.OpenForm "form2", , , , , acDialog
Me.Text17 = Forms!form2.cboByName
DoCmd.Close acForm, "form2"
End Sub

Code on second form:

Private Sub cmdOK_Click()
Me.Visible = False
End Sub
 
Sandra...
Your solution worked perfectly. Especially appreciated was the "plain
English" explanation of how it works. Thanks for your help.

Ivor
Sandra Daigle said:
Hi Ivor,

You can either put code in the first form which pulls the value from the
second form before it closes or put the code in the second form to 'push'
the value to the first form (again) before closing.

Often I will go with the first method - first I open the second form in
'dialog' mode using the acDialog option of the WindowMode paremeter of
docmd.Openform. When used, the code in the first form will pause until the
second form (the one being opened) is either hidden or closed. With this in
mind, on the second form put an 'OK' button which the user clicks to
indicate that a selection has been made. The code behind the OK button
should hide the form (rather than close it). Once the second form is hidden,
the code in original form will resume and can use the value in the control
on the now hidden form to set the value of the combo. Then the second form
is closed by the first form. Here's some sample code:

Code on first Form:

Private Sub Command19_Click()
DoCmd.OpenForm "form2", , , , , acDialog
Me.Text17 = Forms!form2.cboByName
DoCmd.Close acForm, "form2"
End Sub

Code on second form:

Private Sub cmdOK_Click()
Me.Visible = False
End Sub


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Ivor said:
I have a form with a combo box. Typically, an item number is entered in
the combo box and the item description is displayed. Ocassionally, only
the item name is known, so I've created a second form sorted by name
which also displays the item number. I use a command button to open the
second form from the first form. When I choose the appropriate item in
the second form by name, I would like to have the combo box in the first
form updated and the second form close. How can I do this?

Ivor
 
Back
Top