473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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

Similar topics

13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
18
by: Steve | last post by:
Hi I have a really weird problem and any assistance would be welcome. I have developed an app in Access 2002. The app runs perfectly on the development machine. I have packaged the app using...
8
by: Tony Williams | last post by:
I have a form where the user inputs a series of figures into a number of controls. After they've input the total (they don't want the program to create the total) there is a check to make sure the...
2
by: celtic_kiwi | last post by:
I have an Access 97 database, quite large, and have started getting the error, Error 3048: Can't Open any more databases. -The data is split from the application (front end and back end). -The...
9
by: Bill (Unique as my name) | last post by:
Please suggest some links or sources which show how to set up form text boxes in VBA. Thank you so much.
7
by: ljungers | last post by:
Have Form-1 with 3 text boxes and 1 command button. With any of the 3 boxes filled out and button is clicked, a Macro is performed that Opens a Query that has a WHERE clause that uses the 3 test...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.