Y
Yisman
Hi everyone
im setting up a mailmerge in word, which prints out a contract with some db
info. all is fine
after the doc opens i want to find if there is any table in the doc which
the first cell contains a mergefield. if it does then i want to iterate thru
a recordset and copy -paste the cell content several times in that table,
each time with different strings. as an example here is my current code:
With apWord
.Selection.Find.Execute "«FirstName»"
.Selection.Find.Execute
.Selection.SelectCell
.Selection.Copy
Dim rs As New ADODB.Recordset
rs.Open "select * from qrloanborrowers where loanid=" & IDCode,
CurrentProject.Connection
Do Until rs.EOF
.Selection.MoveRight Unit:=wdCell
.Selection.Paste
.Selection.Find.Execute "«FirstName»", , , , , , , , ,
rs!FirstName
.Selection.SelectCell
.Selection.Find.Execute "«LastName»", , , , , , , , , rs!LastName
.Selection.SelectCell
.Selection.Find.Execute "«NationalID»", , , , , , , , ,
Nz(rs!NationalId)
rs.MoveNext
Loop
End With
there are 2 major problems here.
1) i do not know if the "find" method found the mergefield inside a table cell
2) this is the real problem: the replace method, even though it seems that
it works, it actually only replaces a "cover" for the field, but as soon as
the user touches any mailmerge option, everything changes back to the
original value of the original field.
the goal of all this is, because every contract record has multiple people
involved, and i must have a way to fill multiple records onto 1 mailmerge.
thanks
im setting up a mailmerge in word, which prints out a contract with some db
info. all is fine
after the doc opens i want to find if there is any table in the doc which
the first cell contains a mergefield. if it does then i want to iterate thru
a recordset and copy -paste the cell content several times in that table,
each time with different strings. as an example here is my current code:
With apWord
.Selection.Find.Execute "«FirstName»"
.Selection.Find.Execute
.Selection.SelectCell
.Selection.Copy
Dim rs As New ADODB.Recordset
rs.Open "select * from qrloanborrowers where loanid=" & IDCode,
CurrentProject.Connection
Do Until rs.EOF
.Selection.MoveRight Unit:=wdCell
.Selection.Paste
.Selection.Find.Execute "«FirstName»", , , , , , , , ,
rs!FirstName
.Selection.SelectCell
.Selection.Find.Execute "«LastName»", , , , , , , , , rs!LastName
.Selection.SelectCell
.Selection.Find.Execute "«NationalID»", , , , , , , , ,
Nz(rs!NationalId)
rs.MoveNext
Loop
End With
there are 2 major problems here.
1) i do not know if the "find" method found the mergefield inside a table cell
2) this is the real problem: the replace method, even though it seems that
it works, it actually only replaces a "cover" for the field, but as soon as
the user touches any mailmerge option, everything changes back to the
original value of the original field.
the goal of all this is, because every contract record has multiple people
involved, and i must have a way to fill multiple records onto 1 mailmerge.
thanks