ahmedilyas you could use the Mod operator like so: if my Number Mod 2 = 0 then Message Box.
Hi, I would like to validate userform textbox entry for numbers only.
To allow a space in front of after the number you can modify the check If Is Numeric(Trim(Text Box82)) = true Then However, I often like to apply both preventive and corrective measures when I validate data.
By preventive, I mean show the format or show default values.
Here is a smple of the code I'm trying to validate. and your code will yield the same result as mine isn't?
I need to validate the customer code is an integer. Sub showcustomers() While stroutput1 = "" findcustomer = Input Box("Please enter correct customer code", , , 8000, 7000) For n = 1 To 10 If findcustomer = custcode(n) Then stroutput1 = stroutput1 & vb New Line & custname(n) & vb New Line & custaddress(n) & _ vb New Line & custpostcode(n) Chr(13) End If Next n If stroutput1 = "" Then Msg Box ("Name not in list") End If Wend based on my understanding, Davich wanted to verify a user input if its integer or not ("I need to validate the customer code is an integer"... if you entered 12.5 then still its an intege, right?
Back Color = &H80000005 End If End Sub If (Is Numeric(Text Box82) = true) Then will check if the textbox has a numeric value or not.Also I have day and month input limited to 2 characters and year to 4.It works fine with numbers from 10 to 31 and it properly puts an warning message when input is 0 or 32 and on. When I put in numbers from 4 to 9 it puts on a warning message, as I figured out later that program considers empty space after one character input as 0.Unfortunately, Visual Basic's Text Box controls offer a default edit menu that lets users perform any clipboard operation by simply right-clicking on them. You might wonder why you also need to trap the Key Up, Mouse Down, and Mouse Move events: The reason is that you always need to keep track of the last valid position for the insertion point because the end user could move it using arrow keys or the mouse.Fortunately, there's a way around this problem: Instead of trapping a key before it gets to the Text Box control, you trap its effect in the Change event and reject it if it doesn't pass your test. Sel Start End Sub Private Sub Text1_Change() ' Avoid nested calls. The preceding code snippet uses the Is Numeric function to trap invalid data.What if the user pastes an invalid value from the clipboard? Sel Start End Sub Private Sub Text1_Mouse Move(Button As Integer, _ Shift As Integer, X As Single, Y As Single) save Sel Start = Text1.