Solved :-))) Focus To Return To Textbox On Error
Quote from LionelNZ
Hi Folks.
I have SS that I have 3 levels of users using/viewing data and at the
moment it does not allow for errors when inputing password & sheet
number to access. What I need is that if there is an error in password
or sheetnumber ths user gets the choice to re-enter correct data with
vbYesNo or similar. The problem I have is with these lines of code not
getting the focus back to txtSheet to re-enter correct data (>0 & <13).
If Not (txtSheet.Value > 0 And txtSheet.Value < 13) Then
Response = MsgBox(Msg, Style, Title)
[B][COLOR="Red"]If Response = vbYes Then
'frmPassword.Show
txtSheet.SetFocus[/COLOR][/B] :confused:
Else:[B][COLOR="Red"] Exit Sub[/COLOR][/B]
End If
Else
Display More
The above is the offending code with the [COLOR="Red"]Exit Sub[/COLOR] in the wrong place. Below is the code that works : D
'User must enter password & sheet No between
'1 & 12 (numerical months)
If Not (txtSheet.Value > 0 And txtSheet.Value < 13) Then
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
txtSheet.SetFocus
Exit Sub
'If vbNo.......
Else
ActiveWorkbook.Close False
End If
End If
Display More
I will post the whole worksheet with my test pwrds as i know there is fine tuning to do but this will work for the users as they are not overly XL literate.
The purpose of this sheet is to have staff fill in a timesheet while making it idiotproof, limited acess for user, read-only for management by having user insert only one password to gain appropriate access. This is necessary because staff want to be assured that only they
have rw access & only mangement can only view timesheet without making changes as the hese timesheets sit on a public folder on the server.
I will post the file using ths msg number as the reference. I have had a few battles with this code & it can probably be tidied up heaps as long as it meets allof the above constraints.
Pwrds -
User has limited rights (incl copying & pasting graphics for signature) with some unlocked
cells on sheets 1-12 = "staff"
Management = read only on all sheets = "mlvl"
Author/developer - full access = "s"
When distributing this worksheet I protect the VBA.
I hope this helps other users!