Not stopping at text box

A

Afrosheen

First of all, thanks for reading my post.

I have a pass word form. It has three text boxes in it. Userid, Password,
then a username {text8}.
When I open the form on Open I have the Username not show up. This works.
When the person types in their UserId and Password, depending on their user
level the Username will become visible. The Username textbox will show up but
not stop so the person can enter their name. It just goes right by it and
continues on. I've tried to set focus on the textbox but it still goes pass
it and continues on to the next step. What I was wondering is how can I stop
it so the user can put their name in.

Here is the code:

Private Sub Pword_AfterUpdate()
Dim strUser, userpermission, Text8 As String
Dim rst As DAO.Recordset ' The tLogError table
10 strUser = username

Static counter As Integer
20 If StrComp(Me.Pword, Nz(DLookup("Password", "tblpass", "User=" & """"
& strUser & """"), ""), 0) = 0 Then
30 userpermission = DLookup("[userlevel]", "[tblpass]", "[User] = '" &
strUser & "'")

If userpermission = 2 Then
Me.Text8.Visible = True
Me.Text8.SetFocus
End If

40 If userpermission = 3 Then
50 Call MsgBox("Your user level does not qualify you for this
section.", vbCritical, Application.Name)
60 DoCmd.Close acForm, "frmPass2"
70 Exit Sub
80 End If


90 Set rst = CurrentDb.OpenRecordset("tPassLog", , dbAppendOnly)
100 rst.AddNew
110 rst![Date] = Date
120 rst![User] = strUser
130 rst![Time] = Time()
132 rst![Uname] = Text8
140 rst.Update
150 rst.Close

160 strUser = ""
170 username = ""
180 Pword = ""
190 DoCmd.Close acForm, "frmPass2" 'Closes the password window


200 DoCmd.OpenForm "frmFileMaint", acNormal, OpenArgs:=userpermission
210 Exit Sub
220 Else
230 If counter < 2 Then
240 Call MsgBox("Oh Oh! You Didn't Say the Magic Word!!" _
& vbCrLf & "" _
& vbCrLf & "You Only Get 3 Times To Get It Right" _
, vbCritical, Application.Name)

250 strUser = ""
260 username = ""
270 Pword = ""
280 counter = counter + 1
290 Else
300 DoCmd.Close acForm, "frmPass2"
310 End If
320 End If

End Sub

Thanks for the help.
 
J

Jim Burke in Novi

Not sure I'm clear on what you're doing. Do you only allow the users with
userpermission = 2 to proceed? If that's the case, then once they enter the
userid and pw, you should immediately give them the error message if
permission is anything other than 2. You're only checking for values of 2 and
3. Do you have multiple users sharing an ID? Not sure why you'd do it this
way. If you have one ID per user, then there's no need to have them enter
their name - it should just be another field in the permissions table
associated with the ID. If you have multiple users sharing an ID, then after
you've checked the pw, I would just use the InputBox function to have them
enter their name (e.g. userName = InputBox("Please enter your name"). This
will present them with the input box to type in the name, and will then wait
to proceed until they have entered the name and clicked the OK button on the
input box. You'd need to verify that they entered a name before letting them
proceed. Then, once you know they have a valid userid & pw & name, write your
log record (with the user anme set to the value from the Inpu Box), close the
passwrod form and open the other form. It looks like you're expecting the
setfocus to stop the code from running til they enter a value, which it
won't. The way you have your code set up, it will set the focus, write the
log record with a null username value, close the pw form, then open the other
form.


I also wouldn't use the password fiield's after-update event to trigger
processing. I'd have the userID and password as textboxes, with a command
button that they click after they've typed both in. Then prompt for the name
if you have to. Also, it doesn't look like you're checking to make sure they
entered a valid userID before checking the password. Before verifying the pw,
you need to verify that they've entered a valid userID.

Afrosheen said:
First of all, thanks for reading my post.

I have a pass word form. It has three text boxes in it. Userid, Password,
then a username {text8}.
When I open the form on Open I have the Username not show up. This works.
When the person types in their UserId and Password, depending on their user
level the Username will become visible. The Username textbox will show up but
not stop so the person can enter their name. It just goes right by it and
continues on. I've tried to set focus on the textbox but it still goes pass
it and continues on to the next step. What I was wondering is how can I stop
it so the user can put their name in.

Here is the code:

Private Sub Pword_AfterUpdate()
Dim strUser, userpermission, Text8 As String
Dim rst As DAO.Recordset ' The tLogError table
10 strUser = username

Static counter As Integer
20 If StrComp(Me.Pword, Nz(DLookup("Password", "tblpass", "User=" & """"
& strUser & """"), ""), 0) = 0 Then
30 userpermission = DLookup("[userlevel]", "[tblpass]", "[User] = '" &
strUser & "'")

If userpermission = 2 Then
Me.Text8.Visible = True
Me.Text8.SetFocus
End If

40 If userpermission = 3 Then
50 Call MsgBox("Your user level does not qualify you for this
section.", vbCritical, Application.Name)
60 DoCmd.Close acForm, "frmPass2"
70 Exit Sub
80 End If


90 Set rst = CurrentDb.OpenRecordset("tPassLog", , dbAppendOnly)
100 rst.AddNew
110 rst![Date] = Date
120 rst![User] = strUser
130 rst![Time] = Time()
132 rst![Uname] = Text8
140 rst.Update
150 rst.Close

160 strUser = ""
170 username = ""
180 Pword = ""
190 DoCmd.Close acForm, "frmPass2" 'Closes the password window


200 DoCmd.OpenForm "frmFileMaint", acNormal, OpenArgs:=userpermission
210 Exit Sub
220 Else
230 If counter < 2 Then
240 Call MsgBox("Oh Oh! You Didn't Say the Magic Word!!" _
& vbCrLf & "" _
& vbCrLf & "You Only Get 3 Times To Get It Right" _
, vbCritical, Application.Name)

250 strUser = ""
260 username = ""
270 Pword = ""
280 counter = counter + 1
290 Else
300 DoCmd.Close acForm, "frmPass2"
310 End If
320 End If

End Sub

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top