Group:  Microsoft Access ยป microsoft.public.access.modulescoding
Thread: Generating Word documents from access

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Generating Word documents from access
Andy C Matthews 17.07.2006 11:42:02
Hi everyone,
I'm using a slightly modified version of the code kindly provided at
http://www.tek-tips.com/faqs.cfm?fid=2379 to automatically generate a
customer mailing based on a particular form in my Access database. However,
the customer form has a subform on it that shows a number of related parcels
of land as a datasheet view. I need to find a way to have the data (grid
co-ordinate and size) for each field in turn to be inserted into a table
already in this document, bearing in mind there could be a variable number of
land parcels.
Please help!
Kindest regards,
Andy
U.K.
Re: Generating Word documents from access
"Geoff" <geoff[ at ]nospam.com> 17.07.2006 20:47:23
From the description of your problem, it seems it would be easier to create
an Access report using Grouping and Sorting.

Geoff

"Andy C Matthews" <AndyCMatthews[ at ]discussions.microsoft.com> wrote in message
news:D9EC9777-91EE-46CA-BF8C-DE1AD9E4E59B[ at ]microsoft.com...
[Quoted Text]
> Hi everyone,
> I'm using a slightly modified version of the code kindly provided at
> http://www.tek-tips.com/faqs.cfm?fid=2379 to automatically generate a
> customer mailing based on a particular form in my Access database.
> However,
> the customer form has a subform on it that shows a number of related
> parcels
> of land as a datasheet view. I need to find a way to have the data (grid
> co-ordinate and size) for each field in turn to be inserted into a table
> already in this document, bearing in mind there could be a variable number
> of
> land parcels.
> Please help!
> Kindest regards,
> Andy
> U.K.


Re: Generating Word documents from access
Andy C Matthews 18.07.2006 09:02:01
Thanks Geoff, but what I need to be able to do is this:
The following code grabs data from the form and the first record of the
(continous forms) subform and puts it in the word document. I need to have
some form of loop to then jump to the next record of the subform and put that
data into more bookmarks in the word doc, and so on.
Appreciate your help
Andy

--------------------------------------------------

'This function generates a LIT or MISC task letter based on current record
Public Function GenerateLetter(strDocPath As String)

Dim dbs As Database
Dim objWord As Object
Set dbs = CurrentDb

Dim OldPID1 As String
Dim NewPID1 As String
Dim FieldSize1 As String


'Creating a Word object and setting it equal to objWord

Set objWord = CreateObject("Word.Application")

'Filling objWord object with data

With objWord
.Visible = True
.Documents.Open (strDocPath)



'Jump to each bookmark and insert corresponding DB field data
'Inserting SBI
.ActiveDocument.Bookmarks("bmSBI").Select
.Selection.Text = (CStr(Forms!frmMainData!SBI))

'Inserting Field details
'Checks to make sure fields aren't Null before passing data to Word
document
.ActiveDocument.Bookmarks("bmOldPID").Select
If IsNull(Forms!frmMainData!subFields!NewParcelID) Then OldPID1 = ""
Else: OldPID1 = (CStr(Forms!frmMainData!subFields!NewParcelID))
.Selection.Text = OldPID1

.ActiveDocument.Bookmarks("bmNewPID").Select
If IsNull(Forms!frmMainData!subFields!OldParcelID) Then NewPID1 = ""
Else: NewPID1 = (CStr(Forms!frmMainData!subFields!OldParcelID))
.Selection.Text = NewPID1

.ActiveDocument.Bookmarks("bmFieldSize").Select
If IsNull(Forms!frmMainData!subFields!FieldSize) Then FieldSize1 = ""
Else: FieldSize1 = (CStr(Forms!frmMainData!subFields!FieldSize))
.Selection.Text = FieldSize1
Recordset.MoveNext

End With

'Closing object

Set dbs = Nothing
Set objWord = Nothing

End Function



--------------------------------------------------




"Geoff" wrote:

[Quoted Text]
> From the description of your problem, it seems it would be easier to create
> an Access report using Grouping and Sorting.
>
> Geoff
>
> "Andy C Matthews" <AndyCMatthews[ at ]discussions.microsoft.com> wrote in message
> news:D9EC9777-91EE-46CA-BF8C-DE1AD9E4E59B[ at ]microsoft.com...
> > Hi everyone,
> > I'm using a slightly modified version of the code kindly provided at
> > http://www.tek-tips.com/faqs.cfm?fid=2379 to automatically generate a
> > customer mailing based on a particular form in my Access database.
> > However,
> > the customer form has a subform on it that shows a number of related
> > parcels
> > of land as a datasheet view. I need to find a way to have the data (grid
> > co-ordinate and size) for each field in turn to be inserted into a table
> > already in this document, bearing in mind there could be a variable number
> > of
> > land parcels.
> > Please help!
> > Kindest regards,
> > Andy
> > U.K.
>
>
>
Re: Generating Word documents from access
"Geoff" <geoff[ at ]nospam.com> 18.07.2006 12:32:08
Andy:

Yes - I understood your objective. No doubt you realise, the point I was
trying to make before was that, although it is possible to achieve your
objective using Word, it's much more difficult (to use Word) than to create
an Access report that uses Grouping and Sorting. A grouped Access report
would automatically create the output you need using the data from the main
and subforms. However, it seems you have an overriding reason why you must
use Word.

Therefore (if you must use Word), I would not approach this problem by
trying to read data from Textboxes in the subform. Instead, I would write
code to open a recordset on a parameter query that restricted records to
those seen in the subform. Then I would iterate through the recordset,
putting the subform data into the Word document. As you don't know how many
records the subform might contain, your Word document might best put the
subform data into a two-column Word table (for Grid Coordinate and Size).
You can then have just one bookmark pointing to the first cell in the Word
table and use "vbTab" to move to the next cell. If the cursor is in the
last cell of the table, then "vbTab" will add an additional row to the table
for the next record in the recordset.

By the way, I'm not sure you need test for Null. If a form's Textbox is
empty, it returns a zero-length string.

Post back if you need help with any of the above.
Geoff.


"Andy C Matthews" <AndyCMatthews[ at ]discussions.microsoft.com> wrote in message
news:B1C7365B-9DB4-43AA-8FD1-29E3C8567933[ at ]microsoft.com...
[Quoted Text]
> Thanks Geoff, but what I need to be able to do is this:
> The following code grabs data from the form and the first record of the
> (continous forms) subform and puts it in the word document. I need to have
> some form of loop to then jump to the next record of the subform and put
> that
> data into more bookmarks in the word doc, and so on.
> Appreciate your help
> Andy
>
> --------------------------------------------------
>
> 'This function generates a LIT or MISC task letter based on current record
> Public Function GenerateLetter(strDocPath As String)
>
> Dim dbs As Database
> Dim objWord As Object
> Set dbs = CurrentDb
>
> Dim OldPID1 As String
> Dim NewPID1 As String
> Dim FieldSize1 As String
>
>
> 'Creating a Word object and setting it equal to objWord
>
> Set objWord = CreateObject("Word.Application")
>
> 'Filling objWord object with data
>
> With objWord
> .Visible = True
> .Documents.Open (strDocPath)
>
>
>
> 'Jump to each bookmark and insert corresponding DB field data
> 'Inserting SBI
> .ActiveDocument.Bookmarks("bmSBI").Select
> .Selection.Text = (CStr(Forms!frmMainData!SBI))
>
> 'Inserting Field details
> 'Checks to make sure fields aren't Null before passing data to Word
> document
> .ActiveDocument.Bookmarks("bmOldPID").Select
> If IsNull(Forms!frmMainData!subFields!NewParcelID) Then OldPID1 = ""
> Else: OldPID1 = (CStr(Forms!frmMainData!subFields!NewParcelID))
> .Selection.Text = OldPID1
>
> .ActiveDocument.Bookmarks("bmNewPID").Select
> If IsNull(Forms!frmMainData!subFields!OldParcelID) Then NewPID1 = ""
> Else: NewPID1 = (CStr(Forms!frmMainData!subFields!OldParcelID))
> .Selection.Text = NewPID1
>
> .ActiveDocument.Bookmarks("bmFieldSize").Select
> If IsNull(Forms!frmMainData!subFields!FieldSize) Then FieldSize1 =
> ""
> Else: FieldSize1 = (CStr(Forms!frmMainData!subFields!FieldSize))
> .Selection.Text = FieldSize1
> Recordset.MoveNext
>
> End With
>
> 'Closing object
>
> Set dbs = Nothing
> Set objWord = Nothing
>
> End Function


Re: Generating Word documents from access
"Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> 18.07.2006 14:26:01
I can think of one reason for going to Word: everybody on Win9x and above
can read it using WinWord, if nothing else; people who didn't install either
Access or the Snapshot Viewer (both of which are uncommon in many corporate
setups) are out of luck.



Rob


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net