View Full Version : Text Box text


kirkm
12-14-2008, 05:41 PM
I'm typing into a text box and would like to interpret each character
as it's entered.

Textbox name is Text0. My tests with the both the After Update and
Change events are failing.

This gives an empty msgbox each time
Private Sub Text0_Change()
Dim m
'm = SysCmd(SYSCMD_SETSTATUS, Text0) << didn't work
MsgBox Nz(Text0)
End Sub

What is the just-entered character called, if not text0?
Is 'Change' the right event to use?

Thanks - Kirk

ByteMyzer
12-14-2008, 06:15 PM
Try the KeyPress event:

Private Sub Text0_KeyPress(KeyAscii As Integer)

' KeyAscii: the ASCII value of the key just
' pressed while the Text0 field has the focus

End Sub

kirkm
12-14-2008, 07:15 PM
Thanks ByteMyzer. I'm sort of getting there.... the idea was a text box that would
allow only numbers 1001-1441, ignoring any non-numeric chars and enabling an OK button after the 4th entry... but I dunno... can't detect delete so is a bit pointless.

Kirk

pbaldy
12-14-2008, 07:47 PM
In the change event you would have to use the .Text property:

Me.Text0.Text

but I'm not a big fan of testing keystroke by keystroke. I'd use the before update event of the control, or a validation rule.

kirkm
12-14-2008, 08:15 PM
Hi Paul,

Thanks - that was a brilliant suggestion :)
This seems to be working just fine...

Private Sub Text0_Change()
Select Case Val(Me.Text0.Text)
Case 1001 To 1441
Me.btnOK.Enabled = True
Case Else
Me.btnOK.Enabled = False
End Select
End Sub