kaysoo
asked on
Access 2003 VBA to Duplicate a MS Word Table
Dear Experts,
I am using Access 2003 to design a Solution where I required to click a command button from Access Form to transfer a recordset to an opened Word Document.
Assuming in the opened Word Document already contained a single template table(1), but if I need to programmatically create a second table(2) based on the template table(1), the copied table(2) should be located under the template table(1) in the same Word Document Page separated by a single paragraph, how do I do it?
I hv no problem transferring the Access recordset into the table(1), I just need the vba code to duplicate an extra table from template table in same Word page if needed.
Thanks in advance.
I am using Access 2003 to design a Solution where I required to click a command button from Access Form to transfer a recordset to an opened Word Document.
Assuming in the opened Word Document already contained a single template table(1), but if I need to programmatically create a second table(2) based on the template table(1), the copied table(2) should be located under the template table(1) in the same Word Document Page separated by a single paragraph, how do I do it?
I hv no problem transferring the Access recordset into the table(1), I just need the vba code to duplicate an extra table from template table in same Word page if needed.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys, both of your advice gave me a big help with some slight modification of my own.
'To copy the table:
wd.Selection.Tables(1).Sel ect
wd.Selection.Copy
Changed to:
'To copy the table:
mydoc.Tables(1).Select
wd.Selection.Copy
the rest of the codes were combination from both comments and it copy and paste as intended.
Thanks again.
'To copy the table:
wd.Selection.Tables(1).Sel
wd.Selection.Copy
Changed to:
'To copy the table:
mydoc.Tables(1).Select
wd.Selection.Copy
the rest of the codes were combination from both comments and it copy and paste as intended.
Thanks again.
Your welcome, glad I could help.
ASKER
I tried your code, there are no syntax error but the Table wasn't copied and pasted as planned too, then MS Access 2003 pop up a message saying "OBJECT REQUIRE".
What is that means?
I attached a sample document for ref and the coding as well.
Private Sub Command96_Click()
On Error GoTo Err_Command96_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim wd As Object
Set wd = CreateObject("Word.Applica
Set mydoc = wd.Documents.Open("C:\Prog
Set db = CurrentDb()
wd.Visible = True
'To copy the table:
Selection.Tables(1).Select
Selection.Copy
'Then move to where you want to paste the copy. One move example:
Selection.MoveDown Unit:=wdLine, Count:=100
'Then paste what you copied:
Selection.PasteAndFormat (wdPasteDefault)
Exit_Command96_Click:
Exit Sub
Err_Command96_Click:
MsgBox Err.Description
Resume Exit_Command96_Click
End Sub
Sample-Word-Doc.jpg