Text box control errors

GaelicFatboy

Registered User.
Local time
Today, 20:32
Joined
Apr 17, 2007
Messages
100
This is a follow on from a thread posted last week called 'Control focus following "Enter" key press'.

I've got a control called Text_Box1 that I wish to keep the focus on once a number has been entered and the 'Enter' key has been pressed. If I use the follow code the focus stays with the control.

Private Sub Text_Box1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode=13 Then KeyCode=0
End Sub

However, once the 'Enter' key has been pressed I do need to get the number entered into the text box, but it's here that I'm having the diffeculty. Can someone please explain why I'm getting a 'Null' error for the text box contents using the following code and more importantly how can I get round the problem?

Private Sub Text_Box1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim My_Number As Long

If KeyCode=13 Then
KeyCode=0
My_Number=Me.Text_Box1 'this line causes a Null error

Call Get_PartsDetail(My_Number)

End Sub


NB: The text box does contain a long integer number when the 'Enter' Key is pressed.

Cheers for your help

D
 
I suspect the update events aren't happening. Try this:

My_Number=Me.Text_Box1.Text
 
Cheers for that, the ".Text" syntax seems to get over the problem. Simple if you know how, but why is Access so quirky?

Cheers again anyway.

D
 
I wouldn't call it quirky in this case. By avoiding the Enter key you're preventing the textbox from updating, so you have to get the un-updated value (.Text) rather than the stored value (.Value, the default).
 

Users who are viewing this thread

Back
Top Bottom