Show Result on a label on userform

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone;
I have this code from the internet for my login form. I have done some modification to it. Now I wanna do something cooler: I wanna have the attempts left displayed in a label instead of the textbox I have used. I named the textbox Reg1 as in the code below. I believe there is a cooler way. But I cant figure it out yet. Thanks
Kelly

Code:
Option Explicit
Private Trial As Long
Private Sub UserForm_Initialize()
 Reg1.Value = "You have 3 attempts left"
 Reg1.Enabled = False
End Sub
Private Sub cmdCheck_Click()
Dim AddData As Range
Dim user As Variant, Code As Variant, result As Integer, TitleStr As String, _
Current As Range, PName As Variant, UName As Variant, msg As VbMsgBoxResult
user = Me.txtUser.Value
Code = Me.txtPass.Value
TitleStr = "Password check"
result = 0
Set Current = Sheet13.Range("K2")
On Error GoTo errHandler:
Set AddData = Sheet13.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
If user = "SDLS" And Code = "1234M" Then
MsgBox "Welcome Back: -   " & user, vbInformation
AddData.Value = user
AddData.Offset(0, 1).Value = Now
Current.Value = user
Unload Me
Exit Sub
End If

For Each UName In Sheet13.Range("G2:G110")
If user <> "" And Code <> "" And UName = user Then
For Each PName In Sheet13.Range("H2:H110")
If PName = Code Then 'Use this for passcode text
'If PName = CInt(Code) And PName.Offset(0, -1) = user Then ' Use this for passcode numbers only
MsgBox "Welcome Back: -   " & user 
AddData.Value = user
AddData.Offset(0, 1).Value = Now
result = 1
Current.Value = user
Unload Me

Exit Sub
End If
Next PName
End If
Next UName
If result = 0 Then
Trial = Trial + 1
Reg1.Value = "You have" & " " & 3 - Trial & " " & "attempts left"
If Trial < 3 Then msg = MsgBox("Wrong password, please try again", vbExclamation + vbOKOnly, TitleStr)
Me.txtUser.SetFocus

If Trial = 2 Then
    Reg1.Value = "You have" & " " & 3 - Trial & " " & "attempt left"
End If

If Trial = 3 Then
msg = MsgBox("All attempts failed, the form will close…", vbCritical + vbOKOnly, TitleStr)
ActiveWorkbook.Close False
End If
End If
Exit Sub
errHandler:
MsgBox "An Error has Occurred  "
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Thanks very much for pointing to the right direction. I am gratefull.
Kelly
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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