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

Export Data to Word

P: n/a
Hello,
I am trying to create a procedure to export my Access data to a word
template.
I would like to export data from two tables to a word file at the same
time. My two tables are named CASES AND CLIENTS. The word (it is a
template) is named MASTER
To store data, I have created two forms named CASES and MASTER. Since
both forms have a lot of fields, I have added the form CLIENTS as a
SubForm on the form CASES.

I have then created bookmarks on my word template and use this code to
export the data from my table CASES to the template:

Public Function MASTER()
Dim dbs As Database, rstCases As Recordset

Dim appWord As Word.Application
Dim intRecordNo As Integer
Set dbs = CurrentDb()

Set rstCases = Forms!Cases.RecordsetClone
intRecordNo = Forms!Cases!RecordNo
rstCases.Close

'OPEN MS WORD
On Error Resume Next
AppActivate "Microsoft Word"
If Err Then
shell "C:\MSOffice\Office\WINWORD.EXE /Automation",
vbMaximizedFocus
AppActivate "Microsoft Word"
End If
On Error GoTo 0

Set appWord = GetObject(, "Word.Application")

'OPEN THE MASTER TEMPLATE
With appWord
..Documents.Add "C:\MyLibrary\Template.dot"
..ActiveDocument.ShowSpellingErrors = False
'INSERT DATA FROM ACCESS TABLE "CASES"
On Error Resume Next
' NAME
..Selection.Goto wdGoToBookmark, :="Name"
..Selection.TypeText rstCases!Name & ", " Cases!Name

My problem is that I am only able to export the data from the table
CASES to the template.

I would like to be able to also export the data that I will enter in
the subform GUESTS into the same template that in the mean time has
opened as a simple word document (and named document1):

I have tried to simply add the code:
..Selection.Goto wdGoToBookmark, :="Name"
..Selection.TypeText rstCases!Name & ", " Cases!Name

but it does not work. Obviously I need to declare something. Any idea
and help with code?

Thanks.
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
the Three Amigos do this in the Developer Handbook... you can pass the
child recordset to the Word doc and then turn that into a table or
write it to a table... In ADH2000 it's in Chapter 12. See the
CreateTableFromRecordset function they wrote. (I'd be nice and post
it, but I didn't write it...)
Nov 12 '05 #2

P: n/a
Thanks friend, but could you provide me with a link where I can find the code?
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
the Three Amigos do this in the Developer Handbook... you can pass the
child recordset to the Word doc and then turn that into a table or
write it to a table... In ADH2000 it's in Chapter 12. See the
CreateTableFromRecordset function they wrote. (I'd be nice and post
it, but I didn't write it...)

Nov 12 '05 #3

P: n/a

"Paolo" <jp***@tin.it> skrev i melding
news:9f**************************@posting.google.c om...
Hello,
I am trying to create a procedure to export my Access data to a word
template.
I would like to export data from two tables to a word file at the same
time. My two tables are named CASES AND CLIENTS. The word (it is a
template) is named MASTER
To store data, I have created two forms named CASES and MASTER. Since
both forms have a lot of fields, I have added the form CLIENTS as a
SubForm on the form CASES.

I have then created bookmarks on my word template and use this code to
export the data from my table CASES to the template:

Public Function MASTER()
Dim dbs As Database, rstCases As Recordset

Dim appWord As Word.Application
Dim intRecordNo As Integer
Set dbs = CurrentDb()

Set rstCases = Forms!Cases.RecordsetClone
intRecordNo = Forms!Cases!RecordNo
rstCases.Close

'OPEN MS WORD
On Error Resume Next
AppActivate "Microsoft Word"
If Err Then
shell "C:\MSOffice\Office\WINWORD.EXE /Automation",
vbMaximizedFocus
AppActivate "Microsoft Word"
End If
On Error GoTo 0

Set appWord = GetObject(, "Word.Application")

'OPEN THE MASTER TEMPLATE
With appWord
.Documents.Add "C:\MyLibrary\Template.dot"
.ActiveDocument.ShowSpellingErrors = False
'INSERT DATA FROM ACCESS TABLE "CASES"
On Error Resume Next
' NAME
.Selection.Goto wdGoToBookmark, :="Name"
.Selection.TypeText rstCases!Name & ", " Cases!Name

My problem is that I am only able to export the data from the table
CASES to the template.

I would like to be able to also export the data that I will enter in
the subform GUESTS into the same template that in the mean time has
opened as a simple word document (and named document1):

I have tried to simply add the code:
.Selection.Goto wdGoToBookmark, :="Name"
.Selection.TypeText rstCases!Name & ", " Cases!Name

but it does not work. Obviously I need to declare something. Any idea
and help with code?

Thanks.


Helen Feddema's website has many codesamples on how to exhange data between
office application. http://www.helenfeddema.com

Sigurd
Nov 12 '05 #4

P: n/a
It's here. I just found it. Search the NG for "CreateTableFromRecordset".
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.