I'm trying to export (button click) data from Access recordset (data from 2 columns - "Question" & "Answer") to Word template which has FormFields "Question" & "Answer".
I managed to do it but only until Word document runs out of FormFields (which I added - 100), if recordset has more than 100 rows, it will result with an error "error 5941 the requested member of the collection does not exist" - because it run out of available FormFields (at this time max number of questions is 1100, and it will grow). I can, btw, add several thousand FormFields, but then user will have to delete the empty ones when he uses this option.
I feel like there is an easy way to implement some other kind of loop which will take a document which has only these two FormFields and copy or duplicate first FormField - "Question" and insert data in second, but I still didn't find any way of doing that.
Exporting data from 2 columns in Access recordset, one is "Question" and other "Answer". Code on ButtonClick:
Private Sub cmdToWordMultiple_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = Me.RecordsetClone
Set Wd = New Word.Application
Set myDoc = Wd.Documents.Add("C:\Users\User\Desktop\ReportQuestions.docx")
Wd.Visible = True
rst.MoveFirst
Do Until rst.EOF
myDoc.FormFields("Question").Range.Text = Nz(rst!Question, "")
myDoc.FormFields("Answer").Range.Text = Nz(rst!Answer, "")
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
objWord.Application.Quit
End Sub
I would like to make this button export data from Access recordset to Word Document, without leaving excess FormFields.