Detecting spaces in UserForm textboxes

O

Ouka

Hi all,

I'm writting error code to search for empty textboxes in a userform.

Basically I have 4 textboxes that are to be associated with each other
These textboxes represent data pulled off of a spreadsheet that is t
be edited. If there is data in any of the 4, then all 4 must have dat
in them as well. If all 4 are empty, then the record on the spreadshee
is deleted.

My problem is if the user uses the spacebar instead of the Del key t
remove data from the textboxes, then the cells aren't truely empty a
far as VBA is concerned.

How do you make VBA count spacebar values as null value entries?

i.e. make "" = " " = " " = " ", etc?

I'm currently using:

If Controls("Textbox" & N).value <> "" and _
(Controls("Textbox" & O).value = "" or _
Controls("Textbox" & P).value = "" or _
Controls("Textbox" & Q).value = "") then

MsgBox "Error, partially completed treatment detected!"
Exit Sub
End if

Repeated for each of the different textboxes.


Thanks
 
R

ronthedog

Ouka said:
Hi all,

I'm writting error code to search for empty textboxes in a userform.

Basically I have 4 textboxes that are to be associated with each other
These textboxes represent data pulled off of a spreadsheet that is t
be edited. If there is data in any of the 4, then all 4 must have dat
in them as well. If all 4 are empty, then the record on the spreadshee
is deleted.

My problem is if the user uses the spacebar instead of the Del key t
remove data from the textboxes, then the cells aren't truely empty a
far as VBA is concerned.

How do you make VBA count spacebar values as null value entries?

i.e. make "" = " " = " " = " ", etc?

I'm currently using:

If Controls("Textbox" & N).value <> "" and _
(Controls("Textbox" & O).value = "" or _
Controls("Textbox" & P).value = "" or _
Controls("Textbox" & Q).value = "") then

MsgBox "Error, partially completed treatment detected!"
Exit Sub
End if

Repeated for each of the different textboxes.


Thanks!

I'd suggest using LEN to return the length of the string in th
textbox. If it returns zero then your textbox is empt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top