PDA

View Full Version : Checkboxes and Bookmarks



melley
11-04-2010, 09:35 PM
Hi Guys,

I'm bashing my head against brickwall :banghead:.

I haven't done this in a while but I wanted to someone to jog my memory on checkboxes and bookmarks. Basically if a person selects CHK1 it will got to 5 different bookmarks and fill in certain information.

Anyone's help would be fantastic.

jorgenho
11-05-2010, 04:39 AM
Something like this?

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
'goto bookmarks
Selection.GoTo what:=wdGoToBookmark, Name:="myBookmark"
Selection.TypeText "Some Text"
End If
End Sub

Tinbendr
11-05-2010, 05:48 AM
Welcome to VBA Express!

Another option without selecting.

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
UpdateBookmark "BM1", "Checked #1"
UpdateBookmark "BM2", "Checked #1"
UpdateBookmark "BM3", "Checked #1"
UpdateBookmark "BM4", "Checked #1"
UpdateBookmark "BM5", "Checked #1"
End If
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
'http://word.mvps.org/faqs/macrosvba/InsertingTextAtBookmark.htm
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub

fumei
11-05-2010, 10:54 AM
"Basically if a person selects CHK1 it will got to 5 different bookmarks and fill in certain information."

This needs to be clarified. Is the certain information the SAME, going into 5 different locations?

What kind of checkbox? Tinbendr's code refers to an ActiveX control.

Sub CheckAndChange()
If ActiveDocument.FormFields("Check1").Result = True Then
ActiveDocument.FormFields("Text1").Result = "I am checked."
End If
End Sub
In the above example a formfield checkbox has the code as an OnExit procedure.

The procedure makes the formfield Text1 = "I am checked." IT also makes four OTHER fields that refer back to Text1 the same string.

In other words, checking the checkbox makes the string "I am checked" appear in FIVE different locations automatically.

melley
11-06-2010, 02:42 PM
Thank you so much guys. It starting to bring it all back now.