By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

Error message boxes (VBA newbie)

P: 5
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
Share this Question
Share on Google+
4 Replies


P: 5
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

100+
P: 267
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

P: 5
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

100+
P: 267
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.