Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

705 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