Variable number of form fields to Word (1 Viewer)

Richie P

New member
Local time
Today, 03:23
Joined
Jan 21, 2007
Messages
7
Hi Guys,

Got an interesting one for you ;)

I'm designing a MS Access database and I've got a form, with a sub-form that can have a variable number of fields. I need to export this data to a MS Word document template, and I've been able to do this for a fixed number of fields using the document properties and the variables you can specify there.

The problem comes when the sub-form's elements changes. Is there a way of exporting a variable number of fields to a MS Word template?

Less importantly, and I doubt this is easily possible, but is there a way of editing MS Access data in Word so that it saves back to the database?

Hope you guys can help - I'm drawing a complete blank and no-one I know can come up with any ideas.


Current code :-

Private Sub Command21_Click()

On Error GoTo ErrorHandler

Dim appWord As Word.Application
Dim docs As Word.Documents
Dim strLetter As String
Dim strTemplateDir As String
Dim prps As Object

Set appWord = GetObject(, "Word.Application")
strTemplateDir = "G:/Docs/"
strLetter = strTemplateDir & "template.dot"

Set docs = appWord.Documents
docs.Add strLetter

Set prps = appWord.ActiveDocument.CustomDocumentProperties

With prps
.Item("ClientID").Value = Nz(Me![txtClientID])
.Item("Artist").Value = Nz(Me![txtArtist])
.Item("Date").Value = Nz(Me![txtNewEnquiry])
.Item("Company").Value = Nz(Me![txtCompany])
.Item("CTC").Value = Nz(Me![txtCTC])
.Item("Tel").Value = Nz(Me![txtTel])
.Item("Mobile").Value = Nz(Me![txtMobile])
.Item("Email").Value = Nz(Me![txtEmail])

<<This is the bit that needs a loop to export 1/2/3 or more versions of this - hence varaible number of fields>>
' .Item("TripDate").Value = Nz(Me![JobRequestRoute.txtDate])
' .Item("FromTime").Value = Nz(Me![JobRequestRoute.txtFromTime])
' .Item("FromPlace").Value = Nz(Me![JobRequestRoute.txtFromPlace])
' .Item("ToTime").Value = Nz(Me![JobRequestRoute.txtToTime])
' .Item("ToPlace").Value = Nz(Me![JobRequestRoute.txtToPlace])
' .Item("Details").Value = Nz(Me![JobRequestRoute.txtDetails])
<<End>>
End With

With appWord
.Visible = True
.Activate
.Selection.WholeStory
.Selection.Fields.Update
.Selection.MoveDown Unit:=wdLine, Count:=1
End With
 

Users who are viewing this thread

Top Bottom