sendkeys.

buggy2

Board Regular
Joined
Feb 28, 2003
Messages
69
I have designed a login form which runs from an autoexec macro for a database. The functionality is fine except that i need to check the password when the user hits the return key. I presume you can use 'sendkeys "{RETURN}" ' in access, but i am not a fan of it at all.

So the problem is: user hits 'enter' instead of clicking ok and the password is correct, then access should be allowed. I sense this will be standard.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Just signed up for Excel, but thought I'd check out Access board.

Your problem was one I had to work at for awhile, the answer is so simple you are going to hate it. :cool:

All you have to do is set the OK button on your form as the Default. Once you do this it has keyboard focus even though your cursor is placed in your password text box.

I usually will have the focus return to the password text box after someone has entered a wrong password or entered null. Of course the null has to be handled as an error routine.

Here's some code:

Sub CheckPassword()
On Error GoTo err
Dim LookupPassword As String

EnteredPassword = Me.txtPassword

LookupPassword = DLookup("Text", "Entities", "Identity = 'MyPassword'")

If EnteredPassword = LookupPassword Then
MsgBox "Congratulations!"
DoCmd.Close
Else
MsgBox "The password you have entered is incorrect."
Me.txtPassword.SetFocus
End If

Exit Sub

err:
If err = 94 Then
MsgBox "Please enter a password"
Me.txtPassword.SetFocus
Else
MsgBox err & ": " & err.Description
End If
 
Upvote 0

Forum statistics

Threads
1,221,517
Messages
6,160,260
Members
451,635
Latest member
nithchun

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top