Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA text shows as null on key down

Hi

I am trying to allow a user to log into my Access solution when they hit enter
I use the following event but for some reason the password that was typed into txtPW
shows as Null

Private Sub txtPW_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Call oLogin
    End If
End Sub
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Shouldn't Ologin have some arguments (username/password)
Anyway put a breakpoint and check exactly at what control you are pointing and what value it holds
Avatar of Murray Brown

ASKER

In the procedure I gather the text in txtPW and even though there is text in the text box it shows as Null. Is this something to do with the KeyDown event?
Just test it before calling the keydown..maybe the control doesn't looses the focus and Enter clears the password.
Just read the txtPW ..store it in a variable and check again.
Also After Update is a good event for this case
Can you show the code for oLogin?
Is the form bound? Im guessing you are moving on to the next "new and blank" record.

Instead, create a button, and have the login cod in that button. Then look at the properties of that button, find the one called "Default" and set it to true. This means this is the default button when the users presses Enter, and that code will run.
If your oLogin fetches the password from txtPW, that will fail, as it has no value at this point.

You may have to pass it as an argument to oLogin:

Call oLogin(Me!txtPW.Text)

Open in new window

I was using the After_Update evet but it conflicts with the following code that I use to show the password for some reason

Private Sub btnEye_Click()
 
   Dim dtWait As Variant
   If txtPW.InputMask = "Password" Then
        txtPW.InputMask = ""
        dtWait = DateAdd("s", 2, Now) ' 2 Seconds
        Do Until Now > dtWait
           DoEvents
        Loop
        txtPW.InputMask = "Password"
  End If
End Sub
Then remove that.
You should never - as in never - display a password.
ASKER CERTIFIED SOLUTION
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Mark. That worked for me