Which Event

D

DS

I have an unbound field that I type in. When the number of chracters
reach 18 I want a message box to pop up that tells you to stop. I don't
want any input beyond 18 chracters, less is ok.

Heres what I have...
Text0 is where the typing takes place. I tried after update, on chage
before update of the textbox but it only works after you take the focus
off of the textbox. Any help appreciated. Thanks, DS.

Me.Text6 = Len(Me.Text0)
If Me.Text6 > 18 Then
MsgBox "stop"
Else:
End If
 
N

Naeem Azizian

Why you don't use inputmask?

and if you want to use key press, keep the value of the text box in a
variable and then if the lenght of text variable goes beyond 18 then
set the text box value to only 18 characters hold in your variable.
then send an error message.

this way you can even choose which part of the text shall apppear in
the text box, you can cut the string from left or right depending on
your own will.
 
M

Marshall Barton

DS said:
I have an unbound field that I type in. When the number of chracters
reach 18 I want a message box to pop up that tells you to stop. I don't
want any input beyond 18 chracters, less is ok.

Heres what I have...
Text0 is where the typing takes place. I tried after update, on chage
before update of the textbox but it only works after you take the focus
off of the textbox. Any help appreciated. Thanks, DS.

Me.Text6 = Len(Me.Text0)
If Me.Text6 > 18 Then
MsgBox "stop"
Else:
End If


If you want Text6 to update after each keystroke, then you
need to use the Change event AND you need to get the Len of
the Text property.

Me.Text6 = Len(Me.Text0.Text)
 
D

DS

Marshall said:
DS wrote:





If you want Text6 to update after each keystroke, then you
need to use the Change event AND you need to get the Len of
the Text property.

Me.Text6 = Len(Me.Text0.Text)
This worked most greatly!!!!! Funny how one word can change things!

Me.Text6 = Len(Me.Text0.Text)
If Me.Text6 > 18 Then
MsgBox "stop"
Else:
End If

Thank You,
DS
 
D

DS

Douglas said:
Presumably it should. Post your code.
Marshall Barton suggested this and it worked great.
Thank you for your help Douglas!

Me.Text6 = Len(Me.Text0.Text)
If Me.Text6 > 18 Then
MsgBox "stop"
Else:
End If
 
D

DS

Naeem said:
Why you don't use inputmask?

and if you want to use key press, keep the value of the text box in a
variable and then if the lenght of text variable goes beyond 18 then
set the text box value to only 18 characters hold in your variable.
then send an error message.

this way you can even choose which part of the text shall apppear in
the text box, you can cut the string from left or right depending on
your own will.
Presumably it should. Post your code.
This works, but out of couriosity, how would I set the Variable length
to 18?
Thanks
DS


Me.Text6 = Len(Me.Text0.Text)
If Me.Text6 > 18 Then
MsgBox "stop"
Else:
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top