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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export a form field into a Word document

Status
Not open for further replies.

manners

Technical User
Jan 19, 2003
61
GB
Hello.

The database i am doing requires that a certificate be created when all the details have been put in. Is there a way to export a specific field from the form/table into word?

Thanks in advance
 
Automate mailmerge - without a template
faq705-3827
Automate Word Mail Merge From Access
faq705-3237

One of these should help.
 
Thanks redapples for such a quick reply. i am quite new to vb and access and there are a couple of statements that i wasnt 100% sure on, in FAQ705-3237 it says 'you will need to set a reference to word' is this seperate from the code?

the task i have to do does not involve saving the certificate, or doing more than one record at a time. just the user clicks on a button, the certificate is generated and the print is done manually. when they are finished they close without saving the document. is this code still applicable now?

thanks for any replies

brian
 
I didn't write FAQ705-3237 but this is true of both the methods. To add a reference do the following.

in VBA editor click the menu item Tools|References. this opens a dialogue and you can then search a list box of available references. One of these is for Microsoft Word. In the FAQ705-3237 you need to have a field already inserted to the document that coresponds to the field in a recordset (either table or query) in the other FAQ (that I did write - FAQ705-3827) you should be able to add a specific value to a document.

try this modified version (there is a lot at the top of the FAQ that helps you find a document to add too - Ignore that bit)

Code:
Function CreateMergeDoc(UseDDE As Boolean, PrintDoc As Boolean, strDocName)
   Dim WordApp As Word.Application
   Dim WordDoc As Word.Document
   Dim strLetter As String
   Dim strConnect As String

   ' Create an instance of Microsoft Word 2000.
   Set WordApp = CreateObject("Word.Application")

   ' Create a new, empty document.
   Set WordDoc = WordApp.Documents.Open("C:/YourFolder/Certificate.doc")

    With WordApp.Selection
        .TypeText Text:= me.txtCertificateNumber
        'or what ever the field you need to add is.
    End With

    WordApp.Visible = True
End Function

This is written on the hoof and I might have missed something but I imagine this would work. Let me know or play around with it until it does.

Redapples
 
thats great thanks. works a treat. I have just gotta find out how to place the required text at a specific place in the document, would using word bookmarks be the way to go?
 
Possibly (?)
thats as far as I got as it was all I needed. Glad to hear it was helpful.

If I stumble across a solution I will let you know. Please post any findings you come across to spread the good word, either here or in response to my FAQ - FAQ705-3827 and i'll credit you.
 
Try looking in the Selection and Range help sections in the Word VBA help files. This would seem to be the best route to follow.
 
Check help on the folowing:

strDotOpenPathName="C:\Folder\MyDocument.doc"
Set objWord = GetObject(, "Word.Application")
Set objWordDoc = objWord.Documents.Add(strDotOpenPathName)

objWord.ActiveDocument.Bookmarks("YourBookmark").Select
objWord.Selection.TypeText Nz(Me.YourFormField)

Good luck
Hans
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top