Solved

Excel 2010 - Testing Textbox contents.  "Less than zero" or "nothing was input into the textbox"

Posted on 2016-07-18
5
73 Views
Last Modified: 2016-08-19
I have a textbox and would like to test the contents for values less than or equal to zero, or if the field was not even visited by the user

If Val(SalaryEarnings.Value) <= 0 Or ___________

Open in new window


What do I put where the underline is?  ""  or " "  or something else.
I want to test a textbox where the user didn't even click inside of it.
0
Comment
Question by:brothertruffle880
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41717728
Is this a textbox on a userform? Is SalaryEarnings the name of the textbox?
0
 
LVL 31

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41718167
If the user didn't click that TextBox, that TextBox will be empty while submitting the values, why don't you check it then if the SalaryEarnings is completely empty and the user tries to submit the values?

Otherwise you may try something like this....

1) First declare a boolean variable in the beginning of the UserForm Module like this.....
Dim Clicked As Boolean

2) Then on the UserForm Initialize event, write the following code...
Private Sub UserForm_Initialize()
Clicked = False
End Sub

Open in new window


3) Also Place the following code in the UserForm Module (Assuming SalaryEarnings is the Name of the TextBox)
Private Sub SalaryEarnings_Enter()
Clicked = True
End Sub

Open in new window


4) Then you can use the following code to check both your conditions like this.....
If Not Clicked Then
   MsgBox "Either You ignored the SalaryEarnings TextBox.", vbExclamation
   Exit Sub
ElseIf Val(SalaryEarnings.Value) <= 0 Then
   MsgBox "You have entered an invalid value.", vbExclamation, "Invlaid Input!"
   Exit Sub
End If

Open in new window


OR if you wish, you may check both the condition in a single statement like this...
If Val(SalaryEarnings.Value) <= 0 or Not Clicked Then

Open in new window

0
 

Author Comment

by:brothertruffle880
ID: 41740276
Hi Martin Liss:
Yes.  this a textbox on a userform and SalaryEarnings the name of the textbox
0
 

Author Comment

by:brothertruffle880
ID: 41753922
Hi Martin Liss:
 Yes.  this a textbox on a userform and SalaryEarnings the name of the textbox
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41754401
Is there something wrong with Neeraj's solution? If so, what?
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question