Alegro
Alegro

Reputation: 7966

How to prevent the code execution if a textbox is empty?

I want to prevent the code execution if user leave a textbox empty

If tx01.Value = "" Then Exit Sub
If tx01.Value = vbNullString Then Exit Sub  //  also tried

But user can simply write a space (or any number of spaces) and - prevention doesn't work.
I need characters in this box (numeric and nonNumeric), but not only spaces.
How can I do this, pls ?

Upvotes: 3

Views: 6983

Answers (2)

Tony Hopkinson
Tony Hopkinson

Reputation: 20330

something like

if trim(tx01.Value) = "" then Exit sub

Trim removes leading and trailing whitespace characters.

Upvotes: 4

A Developer
A Developer

Reputation: 1031

Try adding a Trim() in the textbox value check.

Upvotes: 4

Related Questions