Clear Button

C

call_me_sol

Hi -

I have a simple find/replace textbox that I use to replace specific
bookmarks within a document. Currently, user inputs values into the
text box, hits a button, and the various bookmarks are replaced with
the contents of the text box.

Now, I want to add a CLEAR button to my text box so the user can start
over. Please note that I only want to wipe out the contents of the
text box (not the entire document) so the user has a fresh text box
with which to start.

One problem, though, is that my current code automatically closes the
text box after all of the replacements have taken place. I need the
auto-close feature to stop.

Here is my existing code:

Private Sub CommandButton1_Click()
Dim oRng As Word.Range
Dim oBMs As Bookmarks
Set oBMs = ActiveDocument.Bookmarks
Set oRng = oBMs("RD").Range
oRng.Text = TextBox1
oBMs.Add "RD", oRng
Set oRng = oBMs("DOS").Range
oRng.Text = TextBox3
Set oRng = Nothing
Set oBMs = Nothing
Unload Me
End Sub


Thank you for any help provided!
 
J

Jezebel

The AutoClose is the 'unload me' statement. Remove it.

Separately, the whole exercise would be much simpler if you used DocProperty
fields instead of bookmarks. Then your code simply needs to set the document
property and update fields. A spin-off benefit is that you can add and
remove the locations in the document where the data is displayed without
having to change your code.
 
C

call_me_sol

Hi -- thank you for your reply.

I should mention that I know nothing about VBA. Everything I have done
thus far has been with the tremendous help of the users on this board.

Can you tell me how to use DocProperty fields?
Can you tell me how to code the CLEAR button?

Thank you for your help.
 
J

Jezebel

Hi -- thank you for your reply.

I should mention that I know nothing about VBA. Everything I have done
thus far has been with the tremendous help of the users on this board.

Can you tell me how to use DocProperty fields?

Go to File > Properties. On the Custom tab, define a property (you can use
your own property names; you're not restricted to the names in the list).
Call it, eg, MyProperty.

In the body of the document, press Alt-F9 to insert a new field. Add the
field code so you end up with { DocProperty MyProperty }. Press F9 to update
it. In VBA, you can set the property using

ActiveDocument.CustomDocumentProperties("MyProperty") = "new value"


Can you tell me how to code the CLEAR button?

TextBox1 = ""
 
C

call_me_sol

Hi -

Thanks for the reply. Unfortunately, the DocProperties option won't
work. The data that the users need will not always be the same which
requires me to use a text box that allows the users to simply input
their free form text.

I removed the "Unload Me" option, and the box doesn't hide as
expected. The problem, though, is that my document is in the
background (the text box is in the foreground) and, as a result, I
cannot select any text in the document). I need a way to keep the
text box on the page while still having the freedom to copy the
document text.

Thanks again!
 
D

Doug Robbins - Word MVP

Please do not start different threads in different newsgroups for what is
the same project.

In one of the other groups, I showed you how to use Document Variables which
is another, preferable alternative to the use of bookmarks.

You also need to start using the commonly accepted terminology so that
others are more likely to understand what you are talking about. Where you
are using the term "text box", you are actually refering to a userform.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top