Password Auto Tab

G

Guest

Good morning everybody...Here's my question:
On my login form, I would like users to enter their password and, when the
password typed is correct and it reached the length of the password stored in
the table, I would like to set the focus to another control automatically
without having the user click or tab to another control. With the code
below, it only works with the first record stored in the table. This is what
I have:

Dim intGoodPW As Integer
Dim intCurrentPW As Integer
Dim strCurrentPW As String
Dim strGoodPW As String

strGoodPW = Password
intGoodPW = Len(strGoodPW)
strCurrentPW = txtPassword.Text
intCurrentPW = Len(strCurrentPW)

If intCurrentPW = intGoodPW Then
If txtPassword.Text = DLookup _
("Password", "tblLogin", "[UserName]='" & Me.Username & "'") Then
cmdOK.SetFocus
MsgBox "Password length=" & intGoodPW & vbCrLf & _
"Current Password length=" & intCurrentPW
Else
'leave here
End If
End If
 
G

Graham Mandeno

Hi Antonio

You have the line:
strGoodPW = Password

What is "Password"? Is this form by any chance bound to tblLogin? If so,
then Password probably contains the Password value from the first record.
That means your code will only work if the password for the current user and
the password in the first record are the same length.

All you should need is:
If txtPassword.Text = DLookup ("Password", "tblLogin", _
"[UserName]='" & Me.Username & "'") Then
cmdOK.SetFocus
End If
 
G

Guest

Graham,

These are the changes I made and it's working...I needed to check the length
of the password stored in the tblLogin for the selected user.

Private Sub txtPassword_Change()

Dim intGoodPW As Integer
Dim intCurrentPW As Integer
Dim strCurrentPW As String
Dim strGoodPW As String

strGoodPW = DLookup("Password", "tblLogin", "[UserName]='" & Me.Username &
"'")
intGoodPW = Len(strGoodPW)
strCurrentPW = txtPassword.Text
intCurrentPW = Len(strCurrentPW)

If intCurrentPW = intGoodPW Then
If txtPassword.Text = DLookup _
("Password", "tblLogin", "[UserName]='" & Me.Username & "'") Then
cmdOK.SetFocus
Else
'nothing
End If
End If
End Sub

Graham Mandeno said:
Hi Antonio

You have the line:
strGoodPW = Password

What is "Password"? Is this form by any chance bound to tblLogin? If so,
then Password probably contains the Password value from the first record.
That means your code will only work if the password for the current user and
the password in the first record are the same length.

All you should need is:
If txtPassword.Text = DLookup ("Password", "tblLogin", _
"[UserName]='" & Me.Username & "'") Then
cmdOK.SetFocus
End If
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Antonio said:
Good morning everybody...Here's my question:
On my login form, I would like users to enter their password and, when the
password typed is correct and it reached the length of the password stored
in
the table, I would like to set the focus to another control automatically
without having the user click or tab to another control. With the code
below, it only works with the first record stored in the table. This is
what
I have:

Dim intGoodPW As Integer
Dim intCurrentPW As Integer
Dim strCurrentPW As String
Dim strGoodPW As String

strGoodPW = Password
intGoodPW = Len(strGoodPW)
strCurrentPW = txtPassword.Text
intCurrentPW = Len(strCurrentPW)

If intCurrentPW = intGoodPW Then
If txtPassword.Text = DLookup _
("Password", "tblLogin", "[UserName]='" & Me.Username & "'")
Then
cmdOK.SetFocus
MsgBox "Password length=" & intGoodPW & vbCrLf & _
"Current Password length=" & intCurrentPW
Else
'leave here
End If
End If
 
G

Graham Mandeno

Hi Antonio

My point was that you do not need to compare the strings AND compare the
length, because if the strings are equal then their lengths MUST be the
same.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Antonio said:
Graham,

These are the changes I made and it's working...I needed to check the
length
of the password stored in the tblLogin for the selected user.

Private Sub txtPassword_Change()

Dim intGoodPW As Integer
Dim intCurrentPW As Integer
Dim strCurrentPW As String
Dim strGoodPW As String

strGoodPW = DLookup("Password", "tblLogin", "[UserName]='" & Me.Username &
"'")
intGoodPW = Len(strGoodPW)
strCurrentPW = txtPassword.Text
intCurrentPW = Len(strCurrentPW)

If intCurrentPW = intGoodPW Then
If txtPassword.Text = DLookup _
("Password", "tblLogin", "[UserName]='" & Me.Username & "'")
Then
cmdOK.SetFocus
Else
'nothing
End If
End If
End Sub

Graham Mandeno said:
Hi Antonio

You have the line:
strGoodPW = Password

What is "Password"? Is this form by any chance bound to tblLogin? If
so,
then Password probably contains the Password value from the first record.
That means your code will only work if the password for the current user
and
the password in the first record are the same length.

All you should need is:
If txtPassword.Text = DLookup ("Password", "tblLogin", _
"[UserName]='" & Me.Username & "'") Then
cmdOK.SetFocus
End If
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Antonio said:
Good morning everybody...Here's my question:
On my login form, I would like users to enter their password and, when
the
password typed is correct and it reached the length of the password
stored
in
the table, I would like to set the focus to another control
automatically
without having the user click or tab to another control. With the code
below, it only works with the first record stored in the table. This
is
what
I have:

Dim intGoodPW As Integer
Dim intCurrentPW As Integer
Dim strCurrentPW As String
Dim strGoodPW As String

strGoodPW = Password
intGoodPW = Len(strGoodPW)
strCurrentPW = txtPassword.Text
intCurrentPW = Len(strCurrentPW)

If intCurrentPW = intGoodPW Then
If txtPassword.Text = DLookup _
("Password", "tblLogin", "[UserName]='" & Me.Username & "'")
Then
cmdOK.SetFocus
MsgBox "Password length=" & intGoodPW & vbCrLf & _
"Current Password length=" & intCurrentPW
Else
'leave here
End If
End If
 

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

Similar Threads


Top