Need Login To Auto Populate Userid Field on Form

  • Thread starter Billy Norris via AccessMonster.com
  • Start date
B

Billy Norris via AccessMonster.com

I have a password routine that works. I have a table of Userid, UserName,
User password.

The password if successful will open an edit form. How can I get the edit
form to populate with the User id from the password routine. Below is my
password code:

Private Sub Submit_Click()
'Simple password routine.

Dim F As Form
Set F = Forms![frmPswrdEdit]

If F!pwd = "awesome" Then GoTo pwd_success

If F!pwd <> "awesome" Then GoTo pwd_invalid
If IsNull(F!pwd) Then GoTo pwd_invalid
If Len(F!pwd) = 0 Then GoTo pwd_invalid

On Error GoTo pwd_trap

pwd_success:
DoCmd.Close acForm, "frmpswrdEdit"
acMenuVer70

DoCmd.OpenForm "frmEdit"
' The following Me!fields are located on the "frmEdit"
Me!DateUpdated = Date
Me!TimeUpdated = Time()
Me!Admin = tbl.Users "Name" 'get User name from User table
Exit Sub
 
K

Klatuu

Billy,

There are a number of issues here. First, you say you have a Users table,
but then your password is hard coded as "awesome". How do you know which
user is trying to log in? Next, GET RID OF THE GOTOs!!!!!! The most glaring
problem here is that your pwd_invalid tag is not in your sub. That is the
worst thing you can do with a goto. Whenever you jump outside the sub you
are in, it will stay resident. You can blow memory with this situation.
Better form would be:

Private Sub Submit_Click()
'Simple password routine.
Dim F As Form
Dim blnDone as Boolean

Set F = Forms![frmPswrdEdit]
do until blnDone
If F!pwd = "awesome" Then
'Here is where you should find the user who is logged in. I can't give you
a solution because I don't know how you know who is logged in.
acMenuVer70
DoCmd.OpenForm "frmEdit"
' The following Me!fields are located on the "frmEdit"
Me!DateUpdated = Date
Me!TimeUpdated = Time()
blnDone = True
Else
If msgbox("Retry or Cancel",vbRetryCancel,"Invalid Password") _
= vbCancel Then
blnDone = True
End If
Loop
DoCmd.Close acForm, "frmpswrdEdit"
Exit Sub

Note that your checks on the password text box for zero length and null are
omitted. They are unnecessary.
 

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