Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print/save doc

Status
Not open for further replies.

dellv1510

Technical User
Sep 12, 2010
2
GB
I have a few word documents (templates) into which i mail merge data from a database. each document obviously has a different name. the mail merged data contains the KEY field from the database (a number which is different for each record).

My question is how is it possible for me have a document (for e.g. docone.dot) saved with a title docone(key).dot? I need the saving of the file and its printing to be done at the click of a button, as the user will be printing many records, and separately saving each document is time consuming and increases the possibility of mistakes. Also this document needs to be saved into a particular folder named after the key number (possibly newly created if nonexistent).

sorry if this is unclear, but 3 things need to happen at once: 1.folder created (if nonexistant), 2.saving with filename containing key number, 3.document needs to be sent to printer.

thank you all ever so much for your help
 
Don't know if you can do it otherwise, but you could program that behind a button. If you're wanting to do it all in Access without ever having to actually open the document, then you'll at least need the MS Word object to control the newly created document from your template each time..

So, your code might be something like this (it's just psuedo-code, I'd have to fiddle around with it in Word VBA probably or look some references up to get it just right):

For this example, I'm going to assume a Button name of MailMerge

(actually, the following link may be of more help to you on the specifics, as to the correct syntax, way to set up the object(s), etc.)

Now to my example for your situation:
Code:
Private Sub MailMerge_Click()
  Dim appWord as New Object 'You'll need the specifics for how to set this part up for sure.
  Dim docT as New appWord.Document

  With docT
    'Add whatever other code you think you need to run..
    .SaveAs "S:/MyWordDocs/docone(" & Me.[key] & ").doc"
  End With

'Add some code at the end to clear out any created objects
End Sub

I can help further if you need, but I think you'll be able to handle this one pretty easily if you look at he example here and compare with the link I posted. If you don't mess with VBA code much (to date), don't worry, it's not as bad as it looks. The VB Editor Window will help you at some steps by giving you the options of what you can do, or giving you hints along the way. It's honestly a very good editor to work with, I think.

Let us know whether this or somethings ends up working for you.
 
Thanks for your help. It's given me a start.

I would like the button to be in msword, which i have no problem doing. I can hopefully get around most of the VB code too (although im a bit rusty). The only part i'm stuck at is assigning a string of merged text to a variable. For e.g. Case_No is the field name which contains "12345", this number changes as i merge different records. Now using VB script, i want to assign whatever Case_No is to a variable. With excel you can point straight to a specific cell, i dont know how its done with merge field.

Your help is appreciated.
 
It sounds like you'll be better off finding the mailmerge fields you need, and finding the correct code for dealing with those. I've never done it, but I wouldn't think it all that difficult to handle.

If your database you mentioned is an Access database, however, you could have a form button there that controls Access and Word, and in doing so, you could grab whatever value(s) you need from within Access, and pass via the code.

Sorry I can't help with the Mail Merge fields and such, but I've just never had the need to do so.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top