Problem: User form is not working properly

Copper Contributor

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
Sheets("DB").Select
Range("A2").Select
Else
MsgBox "Username or Password is incorrect"
Unload UserForm1
UserForm1.Show
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
UserForm1.Show


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!