runtime error 13 - type mismatch - force numeric entry

R

Razz

Hi all
I would like to ensure users only enter a numeric value for on a form
textbox (.txtPrice).

..txtPrice is set to currency format :
InsertAtBookmark("price", FormatCurrency(.txtPrice, 0))

This will elimate the runtime error 13 that occurs if a word rather than a
number is entered.

Thanks in advance.
 
A

Anne Troy

Try something like this:

Sub GetValidData()

Dim vInput As Variant
Dim sPrompt As String
Dim sTitle As String
Dim vDefault As Variant

sPrompt = "Enter a number 1 through 10"
sTitle = "Number Entry"
vDefault = ""

Do
vInput = Application.InputBox(sPrompt, sTitle, vDefault, , , , , 1)
vDefault = CStr(vInput)
Loop Until (vInput >= 1 And vInput <= 10) Or vInput = False

If Not vInput = False Then
MsgBox vInput
End If

End Sub

I got it here: http://www.dicks-blog.com/excel/2004/week22/

**** Hope it helps! ****

~Dreamboat
Excel VBA Certification Coming Soon!
www.VBAExpress.com/training/
********************************
 
R

Razz

Thanks Anne


Anne Troy said:
Try something like this:

Sub GetValidData()

Dim vInput As Variant
Dim sPrompt As String
Dim sTitle As String
Dim vDefault As Variant

sPrompt = "Enter a number 1 through 10"
sTitle = "Number Entry"
vDefault = ""

Do
vInput = Application.InputBox(sPrompt, sTitle, vDefault, , , , , 1)
vDefault = CStr(vInput)
Loop Until (vInput >= 1 And vInput <= 10) Or vInput = False

If Not vInput = False Then
MsgBox vInput
End If

End Sub

I got it here: http://www.dicks-blog.com/excel/2004/week22/

**** Hope it helps! ****

~Dreamboat
Excel VBA Certification Coming Soon!
www.VBAExpress.com/training/
********************************
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Razz > écrivait :
In this message, < Razz > wrote:

|| Hi all
|| I would like to ensure users only enter a numeric value for on a form
|| textbox (.txtPrice).
||
|| .txtPrice is set to currency format :
|| InsertAtBookmark("price", FormatCurrency(.txtPrice, 0))
||
|| This will elimate the runtime error 13 that occurs if a word rather than
a
|| number is entered.
||

Try this, supposing that the textbox is originally called "TextBox1":

'_______________________________________
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

With Me.TextBox1
If Not IsNumeric(.Text) Then
MsgBox "You must enter a number in this text box.", _
vbExclamation, "Not a number"
Cancel = True
.SelStart = 0
.SelLength = Len(.Text)
End If
End With

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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