Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to verify integer or no-integer input 2

Status
Not open for further replies.

Axoliien

Programmer
Aug 19, 2003
166
US
I am needing a way to verify that some text boxes, eg: txtNames and other textboxes, eg: txtNumbers are formatted correctly. I need to ensure txtNames only has character values but no integers, and txtNumbers has only integer values (without a decimal) and no characters. I have looked far and wide and can't come up with anything. Any help please?
 
There are levels to this:

1. The InputMask property may do what you need, for very simple things. It will give the user an error if they don't follow the input mask. By far the simplest, but also less powerful.

2. Each control has a BeforeUpdate() event, in which you can "validate" the data entered before the user is allowed to even leave the control. So if they type "a few thou" under "Billed Amount: $", then you can pop up an error messagebox and Cancel the update, forcing them to enter valid data.

 
Aye, I normally do a lot of error checking and verification with data, however I have never taken it to another level and verified the data is actually only integer values or only text values. I am talking about doing the error checking at the time the user commands to run the insert statement. Right now it verifies that required fields have values and that those values are not empty strings, and that dates are valid by entering through a calendar function, however I have no idea where to start with checking for integer values.
 
Do a
IsNumeric(Nz(txtSomeNumber.Value, "non-numeric")) = True

and there is also an IsDate, and there is also a Val() function which will return a number if there is any sort of number in the string, so you can do:

Val(Nz(txtSomeNonNumeric.Value, "0")) = False

which means "make sure we DON'T find any numbers in that textbox"


And there are probably still other ways.

--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
How about:

Check for integer:

If format(int(val(txtNumbers ))) = txtNumbers then
'it was indeed an integer
else
'there are other characters in there
endif

Check for Alpha:

If IsAlpha(txtNames) then...

where IsAplha is a function that looks at each character in turn, and returns FALSE if it locates a number?
(Maskededit sounds better to me, though...)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top