Hi Dale,
Thank you for your reply. However, the contact information is still not
populating in Frm_ActMster. Frm_NewContact opens great and I put the Save
and Cancel button on it and that works wonderfully also. But when the
form
closes or gets hidden in this case, no contact information appears.
I've edited your code slightly because I am actually trying to pass the
frm_NewCont.Contact_ID to a hidden text box on frm_ActMstr.BPV_Contact3_ID
whose control source is =[cbo_bpv_contact_3].[column](0) and
Frm_ActMstr.ContactName3 is actually a combo box.
So here is the code for GetNewcContact:
Private Sub GetNewContact(ctrl As TextBox)
DoCmd.OpenForm "frm_NewContacts", , , , acFormAdd, acDialog
'Check to make sure the form is still loaded.
If CurrentProject.AllForms("frm_NewContacts").IsLoaded = False Then
Exit
Sub
'Check to see if the new contact was cancelled
If Forms("frm_NewContacts").Tag = "Cancel" Then Exit Sub
'If not cancelled, then the new contact was saved
ctrl.Text = Forms("frm_NewContacts").Controls("Contact_ID").Value
'Close frm_NewCont
DoCmd.Close acForm, "frm_NewContacts"
End Sub
Then in Frm_ActMstr I have this on the double click even of the combo box:
Private Sub CBO_BPV_CONTACT_3_DblClick(Cancel As Integer)
On Error GoTo Err_cbo_BPV_Contact_3_DblClick
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Frm_NewContacts"
stLinkCriteria = "[Contact_ID] =" & Me![BPV_Contact3_ID]
If IsNull(Me!BPV_Contact3_ID) Then
Call GetNewContact(Me.BPV_Contact3_ID)
Else
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
End If
Exit_cbo_BPV_Contact_3_DblClick:
Exit Sub
Err_cbo_BPV_Contact_3_DblClick:
msgbox Err.Description
Resume Exit_cbo_BPV_Contact_3_DblClick
End Sub
--
www.bardpv.com
Tempe, Arizona
Dale Fye said:
Emma,
You could use global variables, but I find this technique to be more
reliable
Open the Frm_NewCont using "acDialog" as the value for the WindowMode
parameter in the Docmd.openform method. By using this WindowMode, code
in
your doubleclick event will be paused, waiting for you to close (or hide)
frm_NewCont.
The critical piece of this is the Hide portion. On frm_NewCont, when
they
close the form (close or cancel buttons click event) , don't close it,
just
hide it (me.visible = False). This will allow the code in your main form
to
continue processing, at which time you can populate the correct control.
In
addition to this, to avoid having to enter the same code in more than one
textboxes doubleclick event, I think I would create a subroutine to
handle
this for you. Since I normally have a Cancel and a Save or Close button
on
forms like this (frm_NewCont), I would also set the forms tag property
(me.Tag = "Cance" or me.Tag = "Saved") so that I can check it from my
subroutine to see whether the addition of the new contact was
accomplished or
cancelled. It and the associated code might look like:
Private Sub txt_ContactName1_dblClick(Cancel as integer)
'Pass the textbox control to the subroutine
Call GetNewContact(me.txt_ContactName1)
End Sub
Private Sub GetNewContact(ctrl as textbox)
docmd.OpenForm "frm_NewCont",,,,, acDialog
'Check to make sure the form is still loaded.
if currentproject.allforms("frm_NewCont").IsLoaded = False then exit
sub
'Check to see if the new contact was cancelled
if forms("frm_NewCont").Tag = "Cancel" then Exit Sub
'If not cancelled, then the new contact was saved
ctrl.text = forms("frm_NewCont").Controls("controlName").Value
'Close frm_NewCont
docmd.close acform, "frm_NewCont")
End Sub
HTH
Dale
--
Don''t forget to rate the post if it was helpful!
Email address is not valid.
Please reply to newsgroup only.