textbox AfterUpdate event 
Author Message
 textbox AfterUpdate event

hallo,
i want excel to check if the value of a textbox that  a user has inserted is
numeric or not. if the value is not numeric excel should come with a message
box like "insert a number!". I tried it with "after update" event but i did
not manage to hold the focus on the textbox (and no other command is
permitted)until a number is inserted.
does anybody know a solution?

tia
lars



Wed, 18 Jun 1902 08:00:00 GMT  
 textbox AfterUpdate event
You may need something along the lines of

Sub Get_Info()
Dim sResp As String
Dim sPrompt As String

sPrompt = "Enter Number"
Do While True
sResp = InputBox(sPrompt)

If Not IsNumeric(sResp) Then
MsgBox "BAD!!"
Else: Exit Do
End If
Loop

End Sub

ITTH
Michael


Quote:
> hallo,
> i want excel to check if the value of a textbox that  a user has inserted
is
> numeric or not. if the value is not numeric excel should come with a
message
> box like "insert a number!". I tried it with "after update" event but i
did
> not manage to hold the focus on the textbox (and no other command is
> permitted)until a number is inserted.
> does anybody know a solution?

> tia
> lars



Wed, 18 Jun 1902 08:00:00 GMT  
 textbox AfterUpdate event
Use the keypress event to examine each key.  Reject entries you don't like.

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 Then
   KeyAscii = 0
 End If
 'Don't allow two periods
 If InStr(TextBox1.Text, ".") And KeyAscii = 46 Then
   KeyAscii = 0
 End If
End Sub

The above restricts entries to the numerals 1 to 9 and the period.

Regards,
Tom Ogilvy
MVP Excel


Quote:
> hallo,
> i want excel to check if the value of a textbox that  a user has inserted
is
> numeric or not. if the value is not numeric excel should come with a
message
> box like "insert a number!". I tried it with "after update" event but i
did
> not manage to hold the focus on the textbox (and no other command is
> permitted)until a number is inserted.
> does anybody know a solution?

> tia
> lars



Wed, 18 Jun 1902 08:00:00 GMT  
 textbox AfterUpdate event
Lars,

Use the Exit event.

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(Me.TextBox1.Text) = False Then
    MsgBox "Enter a number"
    Cancel = True
End If

End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting Services


Quote:
> hallo,
> i want excel to check if the value of a textbox that  a user has inserted
is
> numeric or not. if the value is not numeric excel should come with a
message
> box like "insert a number!". I tried it with "after update" event but i
did
> not manage to hold the focus on the textbox (and no other command is
> permitted)until a number is inserted.
> does anybody know a solution?

> tia
> lars



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. TextBox and AfterUpdate Event

2. AfterUpdate event problem for a textbox on a form

3. AfterUpdate on Textbox fires more than once.

4. setfocus of a textbox AfterUpdate

5. Textbox AfterUpdate problem

6. AfterUpdate For TextBox Not Launching?

7. Unusual BeforeUpdate & AfterUpdate event appearance

8. AfterUpdate event - determining button clicked

9. BeforeUpdate or AfterUpdate Events

10. subform AfterUpdate event


 
Powered by phpBB® Forum Software © phpBB Group