Solved

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

Posted on 2016-07-18
5
59 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 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Martin Liss:
Yes.  this a textbox on a userform and SalaryEarnings the name of the textbox
0
 

Author Comment

by:brothertruffle880
Comment Utility
Hi Martin Liss:
 Yes.  this a textbox on a userform and SalaryEarnings the name of the textbox
0
 
LVL 45

Expert Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

771 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

8 Experts available now in Live!

Get 1:1 Help Now