Passing data back from dialog

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an "Action" form that has a field "ContactID". When the ContactID is
double clicked, a "Contacts" form is opened so the user can add a new record.
When the user is finished entering the contact, they close the form and
return to the Action form.

What I want to do is pass the ContactID number (an autonumber field) back to
the Action form and populate the ContactID field.

I've seen bits and pieces of this answer but can't seem to put it all
together.

Thanks,
Robert
 
Is your contacts form opened in dialog mode?
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 (you could do the same thing with
the double click event on the product control). The code behind the click
event of 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.Productid = Forms!form2.lstProductID
DoCmd.Close acForm, "form2"
End Sub


Code on second form:


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