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