View Single Post
  #18   Report Post  
Carol
 
Posts: n/a
Default

Thanks Jay. I do appreciate the time that you have taken to help me with this
endeavor. I have seen that the field is pretty limited insofar as books go,
but there must be a way to learn this without pestering the folks who already
know it. Where would I find the VBA language and it's meanings? There must
be some documentation somewhere. It all makes sense after you explain it to
me. I suppose it's like anything else then; trial and error and the more you
practice, the better you get? Please feel free to send me any helpful
information at . Thanks again!

"Jay Freedman" wrote:

Hi Carol,

How far off are you? Wellll... pretty far, unfortunately.

First establish what you want to happen when the user clicks the Clear
button. Should all the textboxes on the userform and all the contents of the
bookmarks in the document be set to nothing? (It doesn't make sense to me to
clear only one pair.) Or would it be sufficient to clear only the userform's
boxes, and assume that the user will eventually fill them and click OK, and
the document's bookmarks get refilled then? I'll assume the first choice for
now.

One fact you need is that in VBA there is something known as an empty
string, and it's represented by a pair of double quotes with nothing between
them: "" [This is not the same thing as Null, which the help defines as "A
value indicating that a variable contains no valid data."] You clear a
textbox by setting its text to an empty string, and the same for a bookmark
but then you need to re-insert the bookmark.

Except for clearing the textboxes, the code for the Clear button would be a
lot like that for the OK button, like this (I've only shown the first two
textbox/bookmark pairs, and you need to add all the others):

Private Sub cmdClear_Click()
Dim BMRange As Range

With ActiveDocument
TextBox1.Text = ""
Set BMRange = .Bookmarks("Decedent").Range
BMRange.Text = ""
.Bookmarks.Add "Decedent", BMRange

TextBox2.Text = ""
Set BMRange = .Bookmarks("Venue").Range
BMRange.Text = ""
.Bookmarks.Add "Venue", BMRange

' more here....
End With

ActiveDocument.Fields.Update

End Sub

Notice that, unlike the CommandButton1_Click() we discussed before, you
don't put a Userform1.Hide statement in this procedure because you want the
userform to stay on screen to be filled out.

I don't really have much advice about VBA books. You said you bought
"Writing Word Macros", and that's better than most, but the field is pretty
limited.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org

Carol wrote:
Hello Jay,

I redid my template this morning and received another error and so I
scrapped it and started anew and lo and behold, it's working
perfectly.

So now that I have managed to make this thing work at last I am
emboldened to try yet a different step. I now want to add a clear and
a cancel button to my user form. So this is my seminal stab at coding
it:

Private Sub cmdClear_Click()
BMRange.Text = TextBox1 = True
TextDecedent.Value = Null

How far off am I? And I'd still like to know if you could steer me
toward a good user-friendly book.

Thanks ever so much for your help!