Problem: User form is not working properly

Occasional Visitor

I have made a user login form in Excel 2019, using following code:


Private Sub CommandButton1_Click()

If TextBox1.Text = Sheets("D").Range("I14") And TextBox2.Text = Sheets("D").Range("J14") Then
MsgBox "Welcome to Ambipix Accounting System"
Application.Visible = True
Unload Me
MsgBox "Username or Password is incorrect"
Unload UserForm1
End If
End Sub



But, the problem is that, if i close the form by "QueryClose", in the time of next opening the, User login login form is not opening, rather the workbook opens.

To stop opening the workbook i tried the code:


Private Sub Workbook_Open()
Application.Visible = False

End Sub


But, still problem is not solved.


Can someone help me in this case?


1 Reply
Can you upload a file with the bare minimum content that demonstrates the problem? Remember to edit the cells which contain the credentials so they do not contain anything sensitive!