read a negative number in a text box

russell12
russell12 used Ask the Experts™
on
I need to know how I can write a code in vba to read if a textbox has a negative value.  For example if textbox1.value = "-1" then msgbox "negative value". this is not only restricted to -1, it goes for any "-" value.  Any help will be greatly appreciated!!!  Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
How about this:

If me.txtBoxWithNumber < 0 then
     MsgBox "negative value"
End If

Author

Commented:
ok after I posted this, it came to me!!  This is the solution I did, if it could be improved, I am open for discussion!

Select Case Trim("" & Text7)
Case Is <= 0
MsgBox "negative"
Case Else
MsgBox "postive"
End Select

thanks again in advance!!

Author

Commented:
IrogSinta

We posted at the same time I guess, but I am accepting your solution!  I knew it was easy to do, and when I posted it, I thought about it for a minute and wrote that case statement that worked excellent!!  Thanks though for the quick response!  I really appreciate all the experts on this forum.  Signing up for this forum was the best move I have ever made!!  Thanks for the help!!
Thanks, regarding your solution, I'm not sure what you had in mind when concatenating a null string to your text and then using the Trim function.  I believe if you had just used Select Case Text7 it would work fine too.

Author

Commented:
Well for some reason, when I do not put "Trim", the case statement will not read a null value.  It does not make any sense, because I can write an if statement and it works just fine.  But again, thanks for your help.
Just for future reference, you can always use the Nz function to handle null values.
For instance, Nz(Text7,0) would change a null value to 0.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial