G
Guest
Hi, when I use the following macro to check a user password entry, if the
password is not found I want the textbox to clear and the focus to be back
there, after my "password incorrect" message. All seems ok except that the
very last command in my macro does not work, and the focus is set on another
area (the command button I use to exit). Any help will be grateful.
Private Sub TextBox1_AfterUpdate()
'Load the password database (data01.xlt).
Label01:
newpath = "\\XXX\data" : newfile = "data01.xlt" : ChDir newpath :
Workbooks.Open newfile : col = "D" : ro = 0
'Verify password. Close the password database (data01.xlt).
Label02:
ro = ro + 1 : newro = Str(ro) : MyLen = Len(newro) : ro = Right(newro,
(MyLen - 1)) : findcell = col + ro
Range(findcell).Select : datacheck = ActiveCell.FormulaR1C1
If datacheck = "" Then GoTo Label03
If datacheck <> TextBox1 Then GoTo Label02
'Read the user's name. Close the password database (data01.xlt). Load the
main menu form.
Range("A" + ro).Select : username = ActiveCell.FormulaR1C1
Range("A1").Select : ActiveWorkbook.Close savechanges:=False
Sheets("DATA").Activate : Range("B2").Select ActiveCell.FormulaR1C1 = username
menuform.Show : End
'User password not found. Close the password database (data01.xlt). Return
to the form.
Label03:
ActiveWorkbook.Close savechanges:=False
Msg = "The password you entered has not been recognised" : Style = vbOKOnly
+ vbCritical
Title = "PASSWORD FAILURE" : Response = MsgBox(Msg, Style, Title)
TextBox1 = ""
passwordform.TextBox1.SetFocus
End Sub
password is not found I want the textbox to clear and the focus to be back
there, after my "password incorrect" message. All seems ok except that the
very last command in my macro does not work, and the focus is set on another
area (the command button I use to exit). Any help will be grateful.
Private Sub TextBox1_AfterUpdate()
'Load the password database (data01.xlt).
Label01:
newpath = "\\XXX\data" : newfile = "data01.xlt" : ChDir newpath :
Workbooks.Open newfile : col = "D" : ro = 0
'Verify password. Close the password database (data01.xlt).
Label02:
ro = ro + 1 : newro = Str(ro) : MyLen = Len(newro) : ro = Right(newro,
(MyLen - 1)) : findcell = col + ro
Range(findcell).Select : datacheck = ActiveCell.FormulaR1C1
If datacheck = "" Then GoTo Label03
If datacheck <> TextBox1 Then GoTo Label02
'Read the user's name. Close the password database (data01.xlt). Load the
main menu form.
Range("A" + ro).Select : username = ActiveCell.FormulaR1C1
Range("A1").Select : ActiveWorkbook.Close savechanges:=False
Sheets("DATA").Activate : Range("B2").Select ActiveCell.FormulaR1C1 = username
menuform.Show : End
'User password not found. Close the password database (data01.xlt). Return
to the form.
Label03:
ActiveWorkbook.Close savechanges:=False
Msg = "The password you entered has not been recognised" : Style = vbOKOnly
+ vbCritical
Title = "PASSWORD FAILURE" : Response = MsgBox(Msg, Style, Title)
TextBox1 = ""
passwordform.TextBox1.SetFocus
End Sub