468,301 Members | 1,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Error message boxes (VBA newbie)

Hi, theres a few things I would like a hand with, and unfortunatly I have only been working with VBA on excel for a few weeks, thanks to a module at university, and so I dont have a great deal of knowledge, and need things explained in simple terms.
I have userforms with text boxes, but the only data I want inputted into the boxes is numeric, how do I do this, and also how can I get an error message box to appear if text is entered.
I am using visual basic 6.3 on XP.

Thanks in advance

Nick
Nov 24 '06 #1
4 1888
Also I need to only allow positive numbers to be entered into the text boxes, how would I do this.

Thanks again

Nick
Nov 24 '06 #2
albertw
267 100+
Also I need to only allow positive numbers to be entered into the text boxes, how would I do this.

Thanks again

Nick
hi

open a new method of your textbox -- KeyPress

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If InStr("0123456789" + Chr(8), Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

the only keystrokes your textbox will swallow are figures :)
Nov 24 '06 #3
hi

open a new method of your textbox -- KeyPress

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If InStr("0123456789" + Chr(8), Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

the only keystrokes your textbox will swallow are figures :)
Thanks for the help, but is there anyway I can do it without the keypress, or Ascii parts, as I shouldn't know how to use them for my course!
Nov 24 '06 #4
albertw
267 100+
Thanks for the help, but is there anyway I can do it without the keypress, or Ascii parts, as I shouldn't know how to use them for my course!
hi

you can also call

if IsNumeric(Text1.Text)=True or Val(text1.Text)<0 then
msgbox "Enter only digits and positive values",vbOKOnly+vbExclamation"
Text1.SetFocus
endif

but you can use this statement only after input of data in the textbox
Nov 24 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Peter Frost | last post: by
8 posts views Thread by Tony Williams | last post: by
9 posts views Thread by Bill (Unique as my name) | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.