By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Access and Word

P: 9
I have a report template in MS Word which has a number of blank tables where data needs to be filled apart from some static text.

All the data that should go into these tables are in a MSSQL database with Access as the front end which has all the forms. How do I make Access generate reports on the lines of the template with all the data from the database tables added to the static text?

The template is not just a single page. It is a 5-6 page Word document.
Jun 5 '07 #1
Share this Question
Share on Google+
4 Replies


FishVal
Expert 2.5K+
P: 2,653
I have a report template in MS Word which has a number of blank tables where data needs to be filled apart from some static text.

All the data that should go into these tables are in a MSSQL database with Access as the front end which has all the forms. How do I make Access generate reports on the lines of the template with all the data from the database tables added to the static text?

The template is not just a single page. It is a 5-6 page Word document.

You may write the following code, assuming you have Z:\Template.doc MSWord document having bookmarks on where you want to insert data.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnMSWord_Click()
  3.  
  4.     Dim objApp As Word.Application, objWordDoc As Word.Document
  5.  
  6.     Set objApp = CreateObject("Word.Application")
  7.     Set objWordDoc = objApp.Documents.Open("Z:\Template.doc")
  8.  
  9.     With objWordDoc
  10.         .Bookmarks("Field1").Range = Field1
  11.         .Bookmarks("Field2").Range = Field2
  12.         '..........................
  13.         .Bookmarks("FieldN").Range = FieldN
  14.     End With
  15.  
  16.     objApp.Visible = True
  17.  
  18.     Set objWordDoc = Nothing
  19.     Set objApp = Nothing
  20.  
  21. End Sub
  22.  
  23.  
Jun 6 '07 #2

P: 9
You may write the following code, assuming you have Z:\Template.doc MSWord document having bookmarks on where you want to insert data.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnMSWord_Click()
  3.  
  4.     Dim objApp As Word.Application, objWordDoc As Word.Document
  5.  
  6.     Set objApp = CreateObject("Word.Application")
  7.     Set objWordDoc = objApp.Documents.Open("Z:\Template.doc")
  8.  
  9.     With objWordDoc
  10.         .Bookmarks("Field1").Range = Field1
  11.         .Bookmarks("Field2").Range = Field2
  12.         '..........................
  13.         .Bookmarks("FieldN").Range = FieldN
  14.     End With
  15.  
  16.     objApp.Visible = True
  17.  
  18.     Set objWordDoc = Nothing
  19.     Set objApp = Nothing
  20.  
  21. End Sub
  22.  
  23.  
I tried doing as you said. But there seems to be a bit of a problem with the syntax in a couple of places. Please help me out
Jun 6 '07 #3

Expert 100+
P: 218
Dear confused ;)

Is it feasible to use your Word doc as a merge document, then link the data fields to the Access data?

JAT
Steve
Jun 6 '07 #4

FishVal
Expert 2.5K+
P: 2,653
I tried doing as you said. But there seems to be a bit of a problem with the syntax in a couple of places. Please help me out
Have you referenced Word library?

Tools > References > check "Microsoft Word x.x Object Library"
Jun 7 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.