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

  • Follow


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,
0
Reply Utf 2/17/2010 10:56:01 PM

On Wed, 17 Feb 2010 14:56:01 -0800, DontKnow
<DontKnow@discussions.microsoft.com> wrote:

>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

-- 

             John W. Vinson [MVP]
0
Reply John 2/17/2010 11:37:18 PM


DontKnow wrote:
>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".

-- 
Marsh
MVP [MS Access]
0
Reply Marshall 2/18/2010 12:58:13 AM

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,
"John W. Vinson" wrote:

> On Wed, 17 Feb 2010 14:56:01 -0800, DontKnow
> <DontKnow@discussions.microsoft.com> wrote:
> 
> >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
> 
> -- 
> 
>              John W. Vinson [MVP]
> .
> 
0
Reply Utf 2/18/2010 12:59:01 AM

On Wed, 17 Feb 2010 16:59:01 -0800, DontKnow
<DontKnow@discussions.microsoft.com> wrote:

>
>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?

-- 

             John W. Vinson [MVP]
0
Reply John 2/18/2010 2:03:17 AM

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

 


"John W. Vinson" wrote:

> On Wed, 17 Feb 2010 16:59:01 -0800, DontKnow
> <DontKnow@discussions.microsoft.com> wrote:
> 
> >
> >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?
> 
> -- 
> 
>              John W. Vinson [MVP]
> .
> 
0
Reply Utf 2/18/2010 3:10:01 AM

Thanks Marshal Thats pretty much what John wrote!!

Can you read my reply to John please!!

Cheers,
"Marshall Barton" wrote:

> DontKnow wrote:
> >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".
> 
> -- 
> Marsh
> MVP [MS Access]
> .
> 
0
Reply Utf 2/18/2010 3:15:01 AM

Hi,

Replace 
value = Me.Text3
with
value = Me.Text3.Text

HTH,
Alex.

"DontKnow" wrote:

> 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
> 
>  
> 
> 
> "John W. Vinson" wrote:
> 
> > On Wed, 17 Feb 2010 16:59:01 -0800, DontKnow
> > <DontKnow@discussions.microsoft.com> wrote:
> > 
> > >
> > >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?
> > 
> > -- 
> > 
> >              John W. Vinson [MVP]
> > .
> > 
0
Reply Utf 2/18/2010 4:36:01 AM

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,

"Tokyo Alex" wrote:

> Hi,
> 
> Replace 
> value = Me.Text3
> with
> value = Me.Text3.Text
> 
> HTH,
> Alex.
> 
> "DontKnow" wrote:
> 
> > 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
> > 
> >  
> > 
> > 
> > "John W. Vinson" wrote:
> > 
> > > On Wed, 17 Feb 2010 16:59:01 -0800, DontKnow
> > > <DontKnow@discussions.microsoft.com> wrote:
> > > 
> > > >
> > > >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?
> > > 
> > > -- 
> > > 
> > >              John W. Vinson [MVP]
> > > .
> > > 
0
Reply Utf 2/18/2010 4:46:06 AM

On Wed, 17 Feb 2010 20:46:06 -0800, DontKnow
<DontKnow@discussions.microsoft.com> wrote:

>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?
-- 

             John W. Vinson [MVP]
0
Reply John 2/18/2010 5:18:10 AM

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,

"John W. Vinson" wrote:

> On Wed, 17 Feb 2010 20:46:06 -0800, DontKnow
> <DontKnow@discussions.microsoft.com> wrote:
> 
> >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?
> -- 
> 
>              John W. Vinson [MVP]
> .
> 
0
Reply Utf 2/18/2010 6:01:01 AM

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.

-- 
Marsh
MVP [MS Access]
0
Reply Marshall 2/18/2010 3:00:59 PM

11 Replies
167 Views

(page loaded in 0.155 seconds)

Similiar Articles:


















7/10/2012 10:11:06 AM


Reply: