We're setting a default tempelate for the user in VB6 app,
but they can remove/add/change fields orders (we have two
listboxes lists - one with available fields and another
one with Fields on Router).
I'm thinking I could update the query based on the fields
user selected and insert them programmatically from VB and
then have it bought up for user to view the changes made.
Is this possible?
Many thanks!
If I have understood you correctly then it is possible, but I cannot give
you a complete chunk of code for the task.
You can get/set the Query via
ActiveDocument.MailMerge.DataSource.QueryString
I'm not sure that you would actually need to update the query as long as all
the fields the user needed could always be retrieved by a simple
SELECT * FROM A WHERE ...something...
If you start naming specific fields to retrieve then you will need to be
careful that your QueryString does not exceed a rather short length limit
(about 250 characters I think).
You can get the list of fields in the current data source using
For Each f In ActiveDocument.MailMerge.DataSource.DataFields
Debug.Print f.Name
Next
You could for example insert all the MERGEFIELD fields for the current data
source using
With ActiveDocument
For Each f In .MailMerge.DataSource.DataFields
Selection.Fields.Add Selection.Range, wdFieldMergeField, f.Name
Next
End With
Does that give you enough clues to get started?
Peter Jamieson
MS Word MVP
"Melissa" <mlr...@ctchome.com> wrote in message
news:a70b01c1742d$2a6d96e0$35ef2ecf@TKMSFTNGXA11...
But thanks so much for replying - it was enough to start
somewhere!!!
Melissa
>.
>
i've just seen the code you give for inserting mergefields automatically
which i think is very useful!
is it also possible to instert a character return so that each merge field
appears on a separate line! Please give example.
also, i've created my own save button. Would you know how to check if a
document already exists, and if so display a message informing the user then
cancle the save event.
Thanks
Jado
Would you mind asking these programming questions in a more general VBA
group, for example
microsoft.public.word.vba.beginners ?
The reason I ask is because I do as little programming as I possibly can, so
the material isn't at my fingertips and I do not keep tested examples to
hand. How to insert a carriage return into Word is a general Word
programming question, and to be honest, if you are programming in Word VBA I
think you need to take a little time to work out how to do basic things,
both in VBA and in the Word object model. I'm not in a good position to give
you a tutorial on how to program in Word VBA (but you may find useful
material at http://www.mvps.org/word )
If you're still having problems with mailmerge and field-oriented questions
after that, I'll do what I can.
Peter Jamieson
MS Word MVP
"btconnect" <plo...@hotmail.com> wrote in message
news:loIO7.11788$Sk6.73789@NewsReader...