Clear Word Table Using VBA (1 Viewer)

Frank123

Registered User.
Local time
Today, 10:00
Joined
Jun 29, 2016
Messages
31
Hi, I'm a beginner with VBA and could certainly use some help. I have an Access table that a user inputs information. That information is inserted into a Word table in a Word document at a bookmark by a push of a button. I use the code below to insert the information into the Word table. However, there are times the user may need to delete rows or add new ones in the Access table which obviously will change the information in the Word table when inserted. Is there a way to clear the information in the Word table, without deleting the bookmark, before the revised information is inserted from the Access table?


With apWord.Selection
.Goto What:=wdGoToBookmark, Name:="Table_Start"
End With

Do While Not rs.EOF
With apWord.Selection
.TypeText rs![EquipTypeDesign]
.MoveRight unit:=wdCell, Count:=1
.TypeText rs![EquipQuantity]
.MoveRight unit:=wdCell, Count:=1
.TypeText rs![EquipMake]
.MoveRight unit:=wdCell, Count:=1
.TypeText rs![EquipModel]
.MoveRight unit:=wdCell, Count:=1
.TypeText rs![EquipAge]
.MoveRight unit:=wdCell, Count:=1
.TypeText rs![EquipLocation]
.MoveRight unit:=wdCell, Count:=1
.TypeText rs![EquipCapacity]
.MoveRight unit:=wdCell, Count:=1
.TypeText rs![EquipRecoveryRate]
.MoveRight unit:=wdCell, Count:=1
End With
rs.MoveNext
Loop

'This code deletes the empty last row in the table.
With apWord.Selection
.Tables(1).Rows.Last.Cells.Delete
End With
 

JHB

Have been here a while
Local time
Today, 16:00
Joined
Jun 17, 2012
Messages
7,732
If you still can't get it, then post your database with some sample data and a description how to see your problem. And ofcause also the Word document.
 

Users who are viewing this thread

Top Bottom