Password Userform Not Working

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

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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Code:
temp = WorksheetFunction.VLookup(Me.TextBox2.[COLOR=#006400]Text.Valu[/COLOR]e, [COLOR=#ff0000]Range("Sheet5")[/COLOR], [COLOR=#000080]1[/COLOR], 0)

Perhaps??
Code:
temp = WorksheetFunction.VLookup(Me.TextBox2.[COLOR=#006400]Value[/COLOR], [COLOR=#ff0000]Sheets("Sheet5").Range("B:E")[/COLOR], [COLOR=#000080]4[/COLOR], 0)
 
Last edited:
Upvote 0
Code:
temp = WorksheetFunction.VLookup(Me.TextBox2.[COLOR=#006400]Text.Valu[/COLOR]e, [COLOR=#ff0000]Range("Sheet5")[/COLOR], [COLOR=#000080]1[/COLOR], 0)

Perhaps??
Code:
temp = WorksheetFunction.VLookup(Me.TextBox2.[COLOR=#006400]Value[/COLOR], [COLOR=#ff0000]Sheets("Sheet5").Range("B:E")[/COLOR], [COLOR=#000080]4[/COLOR], 0)



Thanks for this, it moves through the rest of the code fine. but if I enter in incorrect details it still processes the email.

Thoughts?
 
Upvote 0
You need to test if password entered matches the lookup value
Code:
If Me.TextBox3.Value = WorksheetFunction.VLookup(Me.TextBox2.Value, Sheets("Sheet5").Range("B:E"), 4, 0) Then
   Process the email
Else
   Do not process the email
End If

Variable Temp seems to be an unneccessary complication
 
Upvote 0

Forum statistics

Threads
1,215,483
Messages
6,125,065
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top