ChrisPhillips
New Member
- Joined
- Feb 1, 2016
- Messages
- 7
Hi Guys
A little stuck, I am trying to create a form that will ask for an authorisation code. When the code is correct it will send an email to distros but if it is incorrect it will close the form.
The authorisation codes are variable based on the userid and is contained on Sheet5 column B (UN) and E (PW)
I am getting an invalid qualifier when I try it
A little stuck, I am trying to create a form that will ask for an authorisation code. When the code is correct it will send an email to distros but if it is incorrect it will close the form.
The authorisation codes are variable based on the userid and is contained on Sheet5 column B (UN) and E (PW)
I am getting an invalid qualifier when I try it
Code:
Private Sub CommandButton1_Click()
Dim Username As String
Username = TextBox2.Text
Dim password As String
password = TextBox3.Text
'Check to see if data is entered into field: TextBox2.Text
If IsNull(Me.TextBox2.Text) Or Me.TextBox2.Text = "" Then
MsgBox "You must enter your username.", vbOKOnly, "Required Data"
Me.TextBox2.Text.SetFocus
Exit Sub
End If
'Check to see if data is entered into field: TextBox3.Text
If IsNull(Me.TextBox3.Text) Or Me.TextBox3.Text = "" Then
MsgBox "You must enter your Password (case sensitive).", vbOKOnly, "Required Data"
Me.TextBox3.Text.SetFocus
Exit Sub
End If
Dim temp As String
On Error Resume Next
temp = WorksheetFunction.VLookup(Me.TextBox2.Text.Value, Range("Sheet5"), 1, 0)
If Username = temp Then
'****************
Err.Clear
temp = ""
temp = WorksheetFunction.VLookup(Me.TextBox3.Text.Value, Range("Sheet5"), 2, 0)
On Error GoTo 0
If password = temp Then
' Select the range of cells on the active worksheet.
ActiveSheet.Range("A1:B13").Select
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = False
With ActiveSheet.MailEnvelope
.Introduction = "This is an auto generated email."
.Item.To = ""
.Item.CC = ""
.Item.Subject = ""
.Item.Send
Else
MsgBox "Invalid Password, Workbook will close"
Unload Me
'ThisWorkbook.Close (I'm not wanting to go-live with this bit yet, so commented out)
End If
Else
MsgBox "Invalid UserName, Workbook will close"
Unload Me
End If
End Sub