austenr
07-17-2015, 07:30 AM
I have a login form in the attached WB (UserForm1) that seems to work fine but when you debug it you get an error. Here is the code:
Private Sub cmdSubmit1_Click()
Dim Username As String
Username = txtUserNameIn.Text
Dim password As String
password = txtPasswordIn.Text
'Check to see if data is entered into field: txtUserNameIn
If IsNull(Me.txtUserNameIn) Or Me.txtUserNameIn = "" Then
MsgBox "You must enter your username.", vbOKOnly, "Required Data"
Me.txtUserNameIn.SetFocus
Exit Sub
End If
'Check to see if data is entered into field: txtPasswordIn
If IsNull(Me.txtPasswordIn) Or Me.txtPasswordIn = "" Then
MsgBox "You must enter your Password (case sensitive).", vbOKOnly, "Required Data"
Me.txtPasswordIn.SetFocus
Exit Sub
End If
'Check to see if the Username & Password entered is a valid username in the 'User Register'
'****************
If Username = WorksheetFunction.VLookup(Me.txtUserNameIn.Value, Range("UserRegister"), 1, 0) Then
'****************
If password = WorksheetFunction.VLookup(Me.txtUserNameIn.Value, Range("UserRegister"), 2, 0) Then
Sheets("FilterData").Visible = xlSheetVisible
MsgBox "Password & Username Accepted"
Unload Me
Sheets("FilterData").Select
Else
' Sheets("ADMIN").Visible = xlVeryHidden
MsgBox "Username & Password Combination Not Accepted!!"
End If
End If
End Sub
I get a variable undefined on this line:
Username = txtUserNameIn.Text
An additional problem is that if the form validates the user name and password as valid, I want it to show the FilterData sheet but somehow it flips to the ADMIN sheet. Don't see where that is happening or possible.
Private Sub cmdSubmit1_Click()
Dim Username As String
Username = txtUserNameIn.Text
Dim password As String
password = txtPasswordIn.Text
'Check to see if data is entered into field: txtUserNameIn
If IsNull(Me.txtUserNameIn) Or Me.txtUserNameIn = "" Then
MsgBox "You must enter your username.", vbOKOnly, "Required Data"
Me.txtUserNameIn.SetFocus
Exit Sub
End If
'Check to see if data is entered into field: txtPasswordIn
If IsNull(Me.txtPasswordIn) Or Me.txtPasswordIn = "" Then
MsgBox "You must enter your Password (case sensitive).", vbOKOnly, "Required Data"
Me.txtPasswordIn.SetFocus
Exit Sub
End If
'Check to see if the Username & Password entered is a valid username in the 'User Register'
'****************
If Username = WorksheetFunction.VLookup(Me.txtUserNameIn.Value, Range("UserRegister"), 1, 0) Then
'****************
If password = WorksheetFunction.VLookup(Me.txtUserNameIn.Value, Range("UserRegister"), 2, 0) Then
Sheets("FilterData").Visible = xlSheetVisible
MsgBox "Password & Username Accepted"
Unload Me
Sheets("FilterData").Select
Else
' Sheets("ADMIN").Visible = xlVeryHidden
MsgBox "Username & Password Combination Not Accepted!!"
End If
End If
End Sub
I get a variable undefined on this line:
Username = txtUserNameIn.Text
An additional problem is that if the form validates the user name and password as valid, I want it to show the FilterData sheet but somehow it flips to the ADMIN sheet. Don't see where that is happening or possible.