How to use toggle button to open/close a form?

kallenanderson

New member
Local time
Yesterday, 18:31
Joined
Jan 11, 2012
Messages
2
Can someone please show me or guide me to a good resource to figure out how to use a toggle button within one form to open/close a separate form? I would like to have the form appear when the toggle button is clicked and close when the toggle button is clicked again.

For whatever reason, I can't seem to find a good reference for the coding this so I'm just guessing at this point. Below is my latest attempt......

Private Sub ReportsToggleButton_Click()
If 0 Then DoCmd.Close "frmReports"
If 1 Then DoCmd.OpenForm "frmReports"
End Sub

Thanks.
 
You aren't testing the button. It would look like:

Code:
If (Me.ReportsToggleButton) Then
  DoCmd.OpenForm...
Else
  DoCmd.Close...
End If
 
Thanks, Paul.

I took your suggestion and modified it a little. Seems to work well.

Private Sub ReportsToggleButton_Click()
If (Me.ReportsToggleButton) Then
DoCmd.OpenForm "frmReports"
Else
If CurrentProject.AllForms("frmReports").IsLoaded = True Then
DoCmd.Close acForm, "frmReports", acSaveNo
End If
End If
End Sub

Thanks again.
 
Happy to help. I was going to suggest testing for the form being opened and forgot. :o
 

Users who are viewing this thread

Back
Top Bottom