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. > > >
|