-2

When I entered docmd. In my code it worked, until I closed it then it stopped working here is my code .

Private Sub Command1_Click()
    If (Txtusername = "123" And txtpassword = 123) Then
    DoCmd.OpenForm FormName:="Kappa", View:=acNormal, DataMode:=acFormPropertySettings, windowMode:=acWindowNormal
    DoCmd.Close
    Else
        MsgBox "Incorrect Login or Password"
    End If
End Sub
cinemassacres
  • 389
  • 4
  • 16

2 Answers2

0

I expect the form you call is opening then immediately closing (do you see it 'flash') because the opening form gets focus and the DoCmd.Close is acting on form that has focus. The calling form remains open. Specify the form to close.

DoCmd.Close acForm, "form name", acSaveNo

June7
  • 19,874
  • 8
  • 24
  • 34
0

DoCmd.Close closes the object currently having the focus. This is the Form opened in the previous line. I assume that you want to close the Form running this code. So, write:

DoCmd.Close acForm, Me.Name
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188