tell form not to display data from empty boxes

M

Mdmax

Hi, I have a user form with ten textboxes for medications, they create
up to
ten lines of user response data, on a seperate report document.

The bookmarks on the report list the name of the med, the dosage (in
mg),
and times per/day taken. The info from these first 3 boxes print to
one line
on the report, and then a vbcr (carriage return) takes the next
medicine
info, to the next line on the form.

Problem is, the form always generates 10 lines of data (on the report)
even
if the textboxes are blank, since I am using the following code for
each of
the 10 listings:

ActiveDocument.Bookmarks("med1").Range.Text = TextBox9.Text
ActiveDocument.Bookmarks("mg1").Range.Text = TextBox10.Text
ActiveDocument.Bookmarks("per1").Range.Text = TextBox11.Text & vbcr
ActiveDocument.Bookmarks("med2").Range.Text = TextBox12.Text
ActiveDocument.Bookmarks("mg2").Range.Text = TextBox13.Text
ActiveDocument.Bookmarks("per2").Range.Text = TextBox14.Text & vbcr
etc, etc, etc, creates data for each line on the form (up to 10)

It's probably simple, but I would like to tell the user form to "stop"
listing data (on the report), if the next series of textboxes are blank
(empty, or contain no data)?
 
G

Graham Mayor

You would be more likely to get a response to this question if you posted it
in the vba or userforms forums - when In fact you appear to have posted a
similar question a day or so ago. I didn't answer it then as it appeared to
make no sense. With the revised code sample you have posted, the reason that
you are getting all those empty lines is because of the "vbcr" after every
line, which enters a line feed. Conditionally inserting the texts and vbcr
would be a way forward. eg

With ActiveDocument
If TextBox9.Text <> "" then
.Bookmarks("med1").Range.Text = TextBox9.Text
.Bookmarks("mg1").Range.Text = TextBox10.Text
.Bookmarks("per1").Range.Text = TextBox11.Text & vbcr
End If
If TextBox12.Text <> "" then
.Bookmarks("med2").Range.Text = TextBox12.Text
.Bookmarks("mg2").Range.Text = TextBox13.Text
.Bookmarks("per2").Range.Text = TextBox14.Text & vbcr
End If
etc
End With

but if all those bookmarks are at fixed locations, it may not do the trick.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

Mdmax-clulessnoob

It worked perfectly (of course), I know my etiquette is not very refined, and
I hope that I don't ever wear out my welcome with the professionals, I really
have learned alot with this project. Again, many thanks for your advice!
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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