Reserved character

  • Thread starter Philip Thonning Skou
  • Start date
P

Philip Thonning Skou

Hi,
I was hoping somebody could help me. I work for a botanic
garden and are trying to make our herbarium label process
easier. I have created a template of a label in Word and
am exporting data from our database into this word
template. I am having a problem with the macro I have
created to merge the data. It goes to the debugger every
time there is a double quote (") in the data.

a) Is " a reserved character in VB?
b) Is there a way around this problem. I think I need to
keep the " in the data because it is used in fields for
tree height measurements.

Here is the macro for the merge:

Sub merge_default()
'
' merge_default Macro
' Macro recorded 6/27/2003 by PTS
'
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
End Sub

c) The Word template stays open when a merge is
successful. How do I close the word template so it is
only the merged document that stays open?

Thank you in advance!
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Philip,

I am not sure why the double quote would cause a failure with the code.
What happens if you execute the merge from the user interface?

To get the mailmerge main document to close after execution of the merge,
use

Dim mdoc as document
Set mdoc = Documents.Open("[Drive:\Path\Filenameofmaindocument")
With mdoc.Mailmerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
mdoc.Close wdDoNotSaveChanges
End Sub

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
H

Helmut Weber

Hi Philip,
I guess, the problem is somehow related to the fact,
that some databases include fields in double quotes,
when exporting data. In case there is a double quote
inside double quotes the number of all quotes may no
longer be an even number. Still worse, if there are two
double quotes inside double quotes they may be treated
an additional record. I would try first to experiment
with the field delimiter of the export-options of
the database. I think, chr$(182) is pretty save.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, NT 4.0
 
P

Philip Skou

Doug and Helmut - thanks for you replies.

Doug -
I am launching the mailmerge from BG-BASE (collection
management software). The process is this. First the data
is being written to a text file. Then Word is launched
opening the template and then running the merge_default
macro. This is where it goes to the VB debugger when the
data is containing ". I can run the merge if I first go
into the text document that was created from BG-BASE and
delete the ". That's why I thought it was the " that made
the problems.

Thanks
 

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