Determine if a checkbox caption is empty

R

RoVo

I have a userform that outputs selected checkboxes captions to a new
word document. The captions are pulled from a table. However, if a
checkbox is selected that has no caption because of a blank field in
the table, it still writes a blank line. Its not a big deal, but the
end result is unattractive. Ive tried to write code that tests to see
if the caption is empty, then dont write to the new file. But I have
had varied results.

For example, something like this:

If CheckBox1.Caption <> Null And Checkbox1.Value = True then
<code to write to file>
End If

This prevents a checked blank line from writing to the file, but it
also prevents fields that have text in them from writing too.

If CheckBox1.Caption <> "" And Checkbox1.Value = True then
<code to write to file>
End If

This writes all fields selected regardless if there is anything in
them or not.



Any help recieved would be greatly appreciated.

Rob
 
J

Jean-Guy Marcil

RoVo was telling us:
RoVo nous racontait que :
I have a userform that outputs selected checkboxes captions to a new
word document. The captions are pulled from a table. However, if a
checkbox is selected that has no caption because of a blank field in
the table, it still writes a blank line. Its not a big deal, but the
end result is unattractive. Ive tried to write code that tests to see
if the caption is empty, then dont write to the new file. But I have
had varied results.

For example, something like this:

If CheckBox1.Caption <> Null And Checkbox1.Value = True then
<code to write to file>
End If

This prevents a checked blank line from writing to the file, but it
also prevents fields that have text in them from writing too.

If CheckBox1.Caption <> "" And Checkbox1.Value = True then
<code to write to file>
End If

This writes all fields selected regardless if there is anything in
them or not.



Any help recieved would be greatly appreciated.

Have you debugged your code to see what those so-called "empty" captions
actually contain?

Put in a

Msgbox CheckBox1.Caption
Stop

before the If statement to see what is the actual content of the caption,
better yet, do

strCeck = CheckBox1.Caption
Stop

and check the value of the string variable in the Locals window of the VBE.

If the content is actually a number of spaces, try

If Trim(CheckBox1.Caption) <> "" And Checkbox1.Value = True then
<code to write to file>
End If


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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