0
votes

I have two forms Form1 and Form2. From Form1 using a button Form2 is opened. Then afterwards via a button I close Form2. After closing, I see the desktop rather than Form1.

How do I use DoCmd.close so that I return back to Form1?

Also after spending some time testing different forms, i came to know that this problem only occurs when the form i am using is a Split-Form. Forms that i have designed myself return back to the previously active form on DoCmd.Close.

Form1

Code for Button

Private Sub Command7_Click()
DoCmd.OpenForm "Form2", , , , , acDialog
End Sub

Private Sub Form_Load()
DoCmd.Maximize
End Sub

Form2

Code for Button

  Private Sub Command13_Click()
  DoCmd.Close
  End Sub
1
Please add some code to help support your question.AJ X.
Where is the bitton that closes form 2?IntelliData

1 Answers

0
votes

I would have to see your code to see where the error is, do you mean that you see your computer desktop or just the open dashboard of access? If you see the open dashboard, your vba code must be closing Form1. In the past when dealing with this issue I've always used the following code for Form1 and Form2.

'Form1

Private Sub Form_Load()
    DoCmd.Maximize
End Sub

Private Sub OpenForm2_Click()
    DoCmd.OpenForm "Form2"
End Sub

'Form2

Private Sub Button_Click()
    DoCmd.Close
End Sub