Access to Word Automation

Sorry this question has been asked already but I still cant get it to work.

When I run the code MS Word opens but the file doesn't.

Here is what I have tried so far.

I have created a document and placed bookmarks on the sheet and saved it as a .dot

I have ammended the the path on the code to locate my file.

I have checked the referencing and MS Word is referenced.

What else could it be that I am doing wrong?

I tried the example and it worked GREAT!!!

Great little database!!! Very helpful Thank-You!
 
I dont sure that I anderstand all the dialog

but if you want to insert in word value from access

you have to insert in the word bookmark ( or you can also text filed)

put the bookmark axactly where you want to insert the value

and in the access you write this code:
Code:
Dim objwors As Word.Application
Set objWord = CreateObject("word.application")
objWord.Visible = True
objWord.Documents.Add ("C:\report.doc") ' your word file name & path

'go to the bookmark
objWord.ActiveDocument.Bookmarks("a1").Select
'insert the text into the bookmark
objWord.Selection.Text = Me.M_NIVHAN


objWord.ActiveDocument.Bookmarks("a2").Select
'insert the text into the bookmark
objWord.Selection.Text = Me.M_NIVHAN

I attach files to see how its work
 

Attachments

  • untitled.JPG
    untitled.JPG
    52.9 KB · Views: 372
  • untitled1.JPG
    untitled1.JPG
    39.5 KB · Views: 321
Hi 24Sharon


Thanks so much for your help that worked a treat!!!!

Thanks evryone for your help!
 
Yet another question!

This has been an extremely handy thread for me, I've been looking for something just like this!

I do have one question though - would anyone know if it's possible to extend the code to loop through all the results of a query and automatically print off a letter for each of them?

And to make matters worse ;) Is it then possible to change a field on each record printed to stop it recurring in future runs of the query?

Many thanks in advance for any insight!
 
Im not a programmer, ive just sorta been throwin into making databases for small projects so im learning a lot as I go.. and this Topic has been amazingly helpfull thank you!.

I do have one question though.. In the script under

' Specify location of template
strTemplateLocation = "c:\templates\AccessToWord.dot"

Is there a way to make it so the current directory that the database is in, is the default directory that the template will reside? Basicaly, when im done with the database, and they decide to move it to a different directory, i dont want the button to stop working.. but i can tell them like "the dot file must be in the same directory as the MBD"..

that would be a great help! thank you!
 
Create a module and enter the following function code. (Code by Access to Go.)

Then put this line in your code:

strWordTemplate = GetCurrentDBpath(False, True) & "AccessToWord.dot"

Function GetCurrentDBpath(Optional IncludeFileName = True, Optional IncludeFinalBackSlash = True) As String
On Error GoTo GetCurrentDBpath_error

Dim s As String
Dim x As Long

s = CurrentDb.Name
If Not IncludeFileName Then
x = InStrRev(s, "\")
If IncludeFinalBackSlash Then
s = Left(s, x)
Else
s = Left(s, x - 1)
End If
End If

GetCurrentDBpath = s

GetCurrentDBpath_Exit:
Exit Function

GetCurrentDBpath_error:
Select Case Err
Case Else
MsgBox Err & "-" & Error$, vbCritical + vbOKOnly, "Error in module GetCurrentDBpath"
Resume GetCurrentDBpath_Exit
End Select
End Function
 
Hello All,

this is an old thread, so i am having the same problem now with access 2007 and world 2007.
Plus i need to generate many letters sent to children parents automatically automated by an access database containing all the students info.


Any idea how to do that inhere ??

Thank you,
 
Any chance anyone has the updated code for Access 2007? I loaded it and let Access do the update on the code, but it has user defined security parameters that fail.

I am planning on using this script for the model for lots of other reports and was wondering if it is possible to add a module to check to make sure the referenced .dot template is the most current version and if it is not the most current version, to change the pathway to the most current version.
 
try super easy word as an alternative - pretty easy to load up -

it gives the option of picking a letter from a list and merging in to it
Check Super easy word in google.
 
The code from 24sharon is pretty much what I am looking to use for this. The way I have it set-up, the user enters data into a form and when the save button is hit the form exports data to the Word document (I have to have Word as the document is created adn controlled by the gov't) and at the same time saves the item into the database.

Anyone know how to update that code to MS Office 2007?
 
This topic gave great info on going from Access -> Word!!!

But how do we create tables, borders, tabbing, etc, and other types of formatting in the Word Document from Access VB? As of right now it's still a very limiting feature as it can just import straight text only. Is there a way to have VB import the text into specific locations on a preconfigured Word document or Word template?
 
The easiest method is to create bookmarks in your Word document, then using some modified code (like below) open your Word Doc, select the bookmark, fill and save when done.

Code:
Set wrdApp = CreateObject("Word.Application")
wrdApp.Documents.Open ("[B]PATHWAY\DOCUMENT.DOC[/B]")
wrdApp.Visible = True
wrdApp.ActiveDocument.Bookmarks("[B]BOOKMARK_NAME[/B]").Select
    wrdApp.Selection.TypeText ([B]strVARIABLECONTAININGTEXT[/B])
wrdApp.ActiveDocument.SaveAs ("[B]PATHWAY[/B]") & tbl_IncidentReport.IncidentID
wrdApp.Quit
 
How do I insert a Memo type field into Word? I'm getting a type mismatch error or an object error in the last line as Fiber is a Memo type field. Using the Bookmarks function from Access, I can only insert Text strings. Memo fields allow me on the user side to enter new lines rather than a single line text.

Code:
            Case Is = "Material"
            ...
            ...
            .ActiveDocument.Bookmarks("requirement5").Range.text = Me![Property].Form!Thickness & " " & Me![Property].Form!ThicknessUnit
'           [B].ActiveDocument.Bookmarks("requirement6").Range.Text = Me![Property].Form!Fiber[/B]
 

Users who are viewing this thread

Back
Top Bottom