?
Solved

Delete bookmarked text from Word document using Access form checkbox control

Posted on 2005-05-15
6
Medium Priority
?
396 Views
Last Modified: 2012-06-21
I have a new document which launches from Access based off a Word template. Within the new document I have a text string, which I identify with a bookmark. My question...

I would like to be able to delete that entire text string if a checkbox on an access form is selected and if it is not selected not do anything with it. There will be a command button (on the Access Form)  onclick event that should run the code to accomplish this. Any ideas?
0
Comment
Question by:Sherkanowski
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:Simon Ball
ID: 14007244
yes, you will have to launch the word document by opening an word object, passing it the document and then using vba code from access to drive word and have it find that string and delete it, or replace it with "" / null.

Private Sub Command1_Click()
dim string_to_find as string
Dim oApp As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

'then we record a marco within word, and place it in here to do the work.

'using

with oApp
.line1 - find the string
.lin2 - delete the string
end with
End Sub

i'll have a play with this for you tomorrow
0
 

Author Comment

by:Sherkanowski
ID: 14014956
I tried different things using your code but could not get it working
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 14016667
i think we have to look at these one at a time, as your questions are touching upon similar area's..and i think the other one is progressing slowly.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 15

Accepted Solution

by:
Simon Ball earned 2000 total points
ID: 14018389
here's the word code to delete the contents of the bookmark, and th bookmark itself

Dim bkm As Bookmark

For Each bkm In ActiveDocument.Bookmarks

If bkm.Name = "w2" Then
MsgBox bkm.Name
bkm.Select '  selects the bookmarked parag
'deletes the selection
Selection.Delete Unit:=wdCharacter, Count:=1
'delete the bookmark
bkm.Delete

End If
Next bkm

within your word object code, you need to make this  like

(if the word object is called objword)

Dim bkm As Bookmark

For Each bkm In objword.ActiveDocument.Bookmarks

If bkm.Name = "w2" Then
MsgBox bkm.Name
bkm.Select '  selects the bookmarked parag
'deletes the selection
objword.Selection.Delete Unit:=wdCharacter, Count:=1
'delete the bookmark
bkm.Delete

End If
Next bkm

so for the oher question you could replace the selection with the new code.


then you also need to tie this to the access form so that it runs if the boton is clicked etc.
0
 

Author Comment

by:Sherkanowski
ID: 14018556
This worked perfectly! Thank you!!
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 14018600
cool!¬  two down, one to go.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question