empty value in bookmark

  • Thread starter Thread starter Joanne
  • Start date Start date
J

Joanne

I am trying to set bookmarks in my word docs automating from access
using office 2000 on winxp

If a particular bookmark has no value on the form, the code stops
running, so I am trying to use an if then else statement to tell the
code if there is no value, just skip it and go to the next bookmark.

This is the code I am using but it doesn't do the job

If oWordapp.ActiveDocument.Bookmarks.Exists("Street2") = True Then
If oWordapp.ActiveDocument.Bookmarks Is Not Null Then
.Item("Street2").Range.Text = Me!Street2
Else
End If
End If

Could you look at this please and advise me where I am going wrong?
TIA
 
try

If oWordapp.ActiveDocument.Bookmarks.Exists("Street2") Then
oWordapp.ActiveDocument.Bookmarks.Item("Street2").Range.Text = _
Nz(Me!Street2, "")
End If

In yr code, I assume you have a
With oWordapp.ActiveDocument.Bookmarks
End With
statement, correct?

If so, the above lines of code should be placed inside the With/End With
to read something like

With oWordapp.ActiveDocument.Bookmarks
'<< your other actions relating to With statement go here
If .Exists("Street2") Then
.Item("Street2").Range.Text = Nz(Me!Street2, "")
End If
End With

Krgrds,
Perry
 
Perry
Thank you so much for your very prompt reply.
Yes, I do have a with oWordapp.ActiveDocument.Bookmarks
End With statement surrounding the adding of the bookmarks.

The routine works well except that it was stopping if a field had no
value.

In real words what is Nz(me!Street2, "") actually saying. I know that
me!Street2 is referrring to the Street2 control on the form, but I
don't know what Nz or the dbl quotes is saying. I would like to know
so I can understand the syntax better and remember it better for the
future.

My app has 65 docs, only 22 have bookmarks. After user inputs info, I
am opening the 22 docs and setting the bookmarks, saving them, and
giving the user the opportunity to view/print or otherwise manipulate
the docs.
When they exit the program, I want to re-open the 22 docs and make all
the bookmarks = nothing. Can you tell me how to build the statement
that will dump the bookmark values and return the docs empty for the
next time the app is needed?

Again, thanks for your expertise. I would really not be getting close
to shipping this if it were not for these great newsgroups.
Joanne
 
Hi Joanne,

What better explanation of the NZ() than below url
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/off2000/html/acfctnz.asp

Very usefull resource this entire library site, bookmark it
(nice pun)

code snip/
dim bkm as word.bookmark
for each bkm in owordapp.activedocument.bookmarks
'first delete bookmark text in the document
bkm.Range.Text = ""
'then erase the bookmark
bkm.Delete
next
/code snip
whereby owordapp is a valid object variable pointing to the Word application
Play around with above code snip ..

Krgrds,
Perry
 
Yes, nice pun - You can bet I will use this resource to help me learn
and quit bugging all you mvps on these newsgroups.

Thank you for the help in deleting the value of the bookmarks. I don't
actually want to delete the bookmark, but I understand enough of what
you wrote to know what to do and what to eliminate. I will simply make
the text in the bookmarks = "" (equal to nothing) and keep the
bookmarks in the docs for the next time the app is needed.

Just hanging around these newsgroups is worth a class in itself
 
Hi Perry
Am trying to set the bookmarks to nothing, but with using the NZ
function, I'm not sure how to set it to nothing, as it already has a
dble quotes in the statement.
I tried deleting the nz statement and just put
.Item("Fname").Range.Text = ""
but it is unhappy and will not delete the bookmark.
So I'm wondering about the syntax of the current nz function and how
to set it to nothing if it is 'not nothing' already. (seems like I'm
talking in a circular argument!!)

Here is the code setting the bookmark if it is present
If oWordapp.ActiveDocument.Bookmarks.Exists("FName") = True Then
.Item("Fname").Range.Text = Nz(Me!FName, "")
End If

Can it be so simple as
.Item("Fname").Range.Text = Nz(Me!FName, "") = ""

Thanks again for your time and expertise
 
Perry
I tried your code snip for deleting the value in the bookmarks,
dim bkm as word.bookmark
for each bkm in owordapp.activedocument.bookmarks
'first delete bookmark text in the document
bkm.Range.Text = ""
'then erase the bookmark
bkm.Delete
next
but it doesn't do it.

Am I missing something here?
Joanne
 
Back
Top