Delete bookmark when checkbox value is false

J

joseph

I am extremely new to this, and don't know a lot of basic things. I've
created a template for a legal document, as well as a userform. Among other
things, the userform compiles a list of attorneys. I only want attorneys on
that list if they satisfy BOTH of two criteria. If they don't satisfy the
second criterion, then I want the bookmark and the hard return deleted, so
there's not a blank space in the middle of the list. This may be wrong, but
the bookmarks look like this:

[bookmark Atty1]
[bookmark atty2]
[bookmark atty3]
etc.

If Attorney 2 does not fit the criteria, right now my code is giving me this:

Attorney 1

Attorney 3,

When I really want this:

Attorney 1
Attorney 3

Here's my code (not my forte, as I'm sure you can tell):

Dim strAtty1 As String
Dim strAtty2 As String
Dim strAtty3 As String

etc...

If chkCertified = True And chkCalifornia = True Then strAtty1 = "John
Attorney, Certified California"
If chkCertified = True And chkCalifornia = False Then strAtty1 = "John
Attorney, Certified Out of State"
If chkCertified = False Then strAtty1 = ""

So, I want to list the attorney who is certified, whether in California or
not. But, I don't want him on the list if he isn't certified anywhere.
Right now, I know I'm telling the code to input a blank space "" because I
don't know how else to do it.

I would like Bookmark2 AND the hard return, to completely disappear, rather
than show a blank space, if the attorney isn't certified.

I really appreciate your help. I'm in over my head....
 
H

Helmut Weber

Hi Joseph,

something along this line:

ActiveDocument.Bookmarks("test").Range.Paragraphs(1).Range.Delete

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
J

joseph

Helmut,

Wouldn't that delete the bookmark regardless of its value?

I think I want to put an if statement under ActiveDocument such as:

With ActiveDocument
If strAtty1 = "" Then .Bookmarks("Atty1").Range.Paragraphs(1).Range.Delete
Else .Bookmarks("Atty1").Text = strAtty1

I'm sure that code is not right -- I'm not a code writer -- would something
like that work? Will you help me with it?

Thanks,
Joseph
 
H

Helmut Weber

Hi Joseph,

your code isn't so far from what you want:

Sub Mytest()
Dim strAtty1 As String
' strAtty1 = "xxx"
With ActiveDocument
If strAtty1 = "" Then
.Bookmarks("Test").Range.Paragraphs(1).Range.Delete
Else
.Bookmarks("Test").Range.Text = strAtty1
End If
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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