Solved

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

Posted on 2016-07-18
5
63 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
  • 2
  • 2
5 Comments
 
LVL 46

Expert Comment

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

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 46

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now