Murray Brown
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
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
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
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.
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:
You may have to pass it as an argument to oLogin:
Call oLogin(Me!txtPW.Text)
ASKER
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
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.
You should never - as in never - display a password.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Mark. That worked for me
Anyway put a breakpoint and check exactly at what control you are pointing and what value it holds