Ho wto trigger an event after entering a number in a text box

D

DontKnow

Hi Guys,

I want ot be able to trigger an event to occur after i enter a number into a
text box. For instance If i have a text box and I enetr a number into the
text box I want to activate the code wiothout pressing the enter key or by
moving the mouse. How would I do that??

I have already tried a few things to noavail. I have tried:
a. On Mouse Move
b. On Lost Focus
c. On Dirty

It is updated of course when you press the "enter" key, but I want the text
box to be updated as soon as a number button is pressed. ie without having to
press the "enter" key.


Any help would be much appreciated.

Cheers,
 
J

John W. Vinson

Hi Guys,

I want ot be able to trigger an event to occur after i enter a number into a
text box. For instance If i have a text box and I enetr a number into the
text box I want to activate the code wiothout pressing the enter key or by
moving the mouse. How would I do that??

I have already tried a few things to noavail. I have tried:
a. On Mouse Move
b. On Lost Focus
c. On Dirty

It is updated of course when you press the "enter" key, but I want the text
box to be updated as soon as a number button is pressed. ie without having to
press the "enter" key.


Any help would be much appreciated.

Cheers,

so you want only one character in the field? The user will never enter a
number such as 10, or 312?

If so, you use the Change event of the control, which fires at every
keystroke. You will need to refer to the control's Text property rather than
the default Value property, because the Value is only set when Access knows
that you're done entering the number. E.g.

Private Sub txtYourTextbox_Change()
If Me!txtyourTextbox.Text = "1" Then ' the user typed 1
<do something with the user's input>
End Sub
 
M

Marshall Barton

DontKnow said:
I want ot be able to trigger an event to occur after i enter a number into a
text box. For instance If i have a text box and I enetr a number into the
text box I want to activate the code wiothout pressing the enter key or by
moving the mouse. How would I do that??

I have already tried a few things to noavail. I have tried:
a. On Mouse Move
b. On Lost Focus
c. On Dirty

It is updated of course when you press the "enter" key, but I want the text
box to be updated as soon as a number button is pressed. ie without having to
press the "enter" key.

If it's a single key stroke, use the Change event.
Otherwise provide more details about the "number".
 
D

DontKnow

Many thanks John for your input,

I still need to click on the form to enable access to see the new value that
I have entered. I was hoping to be able to have the form recognise as soon
as I input the number into the text box, and enable the code to be activated
the instant that I press the number into the text box. Is that possible?

cheers,

Cheers,
 
J

John W. Vinson

Many thanks John for your input,

I still need to click on the form to enable access to see the new value that
I have entered. I was hoping to be able to have the form recognise as soon
as I input the number into the text box, and enable the code to be activated
the instant that I press the number into the text box. Is that possible?

Ummmm...

how is the user going to type anything into the textbox without selecting the
textbox, either with the mouse or by tabbing into it??????

The Change event will fire at the first keystroke (on any key) into the
control.

Could you explain just what result you want to happen, and what this number
is?
 
D

DontKnow

Hi Guys,

here is my code:
Dim value As String
value = Me.Text3
Me.Text5 = "From" & " " & Format(Date, "dd-mmm-yyyy") & " " & "To" & " " &
Format(DateAdd("m", Me.Text3, Date), "dd-mmm-yyyy")
Me.Text5.Requery

Text5: is a text box that shows how many months ahead of todays date
Text 3 is the input number that you enter the number of months into.

The trouble that I have is that when I input a number into text box 3, the
number that is shown in the code at "value = Me.Text3" is the number that was
eneterd before. ie. if the number in the box is 5, and I enter another number
say 7, the code utilses/processes 5 and not 7??

Any help is appreciated!!

Cheers
 
D

DontKnow

Thanks Marshal Thats pretty much what John wrote!!

Can you read my reply to John please!!

Cheers,
 
D

DontKnow

Tokyo,

Your a genious, that actually works!! before I tried adding the ".Text" I
did not think it would work...

To my amazement it did!!

Many thanks,
 
J

John W. Vinson

Your a genious, that actually works!! before I tried adding the ".Text" I
did not think it would work...

ummm... I *DID* say to use the .Text property. You didn't. That's why it
didn't work.

As written you can only use nine months or fewer; is that OK?
 
D

DontKnow

Sorry John,
Yes you are correct, you did show me this...

Private Sub txtYourTextbox_Change()
If Me!txtyourTextbox.Text = "1" Then ' the user typed 1

Thanks for your input!!
Cheers,
 
M

Marshall Barton

Ok. you're happy with using the Text property in the change
event, but you still need to guard against a user entering
weird things like ABC, 1234567, or whatever.

It seems like the minimum you need to do is make sure the
Text property can be converted to a month number:

Dim intMonthNum As Integer
If Not Me!txtyourTextbox.Text Like "*[!0-9]*" Then
intMonthNum = Val(Me!txtyourTextbox.Text)
If intMonthNum >= 1 And intMonthNum <= 12 Then
'user enterd a valid month number
Exit Sub
End If
End If
Beep
Me!txtyourTextbox.Text = ""

But, the code will run twice if the user enters 10, 11 or 12
so I really do not like this whole idea you are pursuing.
 

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