Calling one form from inside the other than closing

Griztkojr

Registered User.
Local time
Today, 10:20
Joined
Sep 14, 2011
Messages
10
Hello Everyone:

I have one button on Form A that calls Form B. In Form B I have in Private Sub Form_AfterUpdate():

Forms!FormA!CbComboBox.Requery
End Sub

It works fine if I call Form B from Form A, but if I load Form B by itself (not from the button, but directly) I get an error message when I click on the close button on FORM B.

It seems it is trying to Requery Form A but I do not know how to tell the Form B that it was not loaded from Form A but directly.

Sorry if I am not making to much sense.

Best regards,

G.E.
 
Welcome to the forum


You could use something like;
Code:
If CurrentProject.AllForms("FormA").IsLoaded = True Then
     DoCmd.Close acForm, "FormA"
End If
 
Thank you for your prompt reply John. Where do I put this code? Do I still leave the requery on Form B. Please keep in mind that the Requery is for Form A through Form B but sometimes Form B is loaded without loading Form A so the requery becomes invalid.
 
You would put the code in the On Click event of you Close Button on Form B. The full code might look something like;
Code:
If CurrentProject.AllForms("FormA").IsLoaded = True Then
     DoCmd.Close acForm, "FormA"
     DoCmd.Close acForm, "FormB"
Else
     DoCmd.Close acForm, "FormB"
End If
 

Users who are viewing this thread

Back
Top Bottom