Open and Close Pop up form with one Command Button

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

Guest

Is there a way to close a pop up form by clicking the same command button
that was used to open it?
 
Yes, on your commandbutton click event, chk to see if the pop up form is open
if (currentproject.allforms("formName").Isloaded) then
docmd.close acform, "formName", acSaveYes
 
Try this

Put this in the sub for the command button

Dim intX As Integer
Dim intCount As Integer
intCount = Forms.Count - 1
For intX = intCount To 0 Step -1
If Forms(intX).name = "myform" Then
DoCmd.Close acform,Forms(intX).name
Exit Sub
End if
Next
DoCmd.OpenForm "myform"

change myform to your forms name
 
Jeff said:
Yes, on your commandbutton click event, chk to see if the pop up form
is open if (currentproject.allforms("formName").Isloaded) then
docmd.close acform, "formName", acSaveYes

Good suggestion, but why "acSaveYes"? Do you really want to save design
changes to the form without prompting?
 
Back
Top