PDA

View Full Version : Solved: Check Bookmark value and show in textbox on a form



Rico
04-26-2006, 12:36 AM
Hi all

Info: I have a document containing a bookmark (always 8 characters). When the users are opening the document for the first time a form popup and ask the users for a value to the bookmark. Next time they opens the document I would like the document to check if the bookmark value is empty or not.

If empty the initial form “insert value” shall popup and if not a “do you want to change value” form shall popup.


Where do I stand? :think:

Inserting the value from textbox on form works fine, using:


Private Sub cmdOK_Click()

Application.ScreenUpdating = False
With ActiveDocument
.Bookmarks("MyBookmark").Range.Text = txtMyTextbox.Value
End With

Application.ScreenUpdating = True
Unload Me

End Sub


Changing the value in bookmark with value from textbox on form works fine, using:


Private Sub cmdChange_Click()
ActiveDocument.Bookmarks("MyBookmark").Select
Selection.Delete Unit:=wdCharacter, Count:=8

ActiveDocument.Bookmarks.Add Range:=Selection.Range, _
Name:="MyBookmark"

Application.ScreenUpdating = False

With ActiveDocument
.Bookmarks("MyBookmark").Range.Text = txtMyTextbox.Value
End With

Application.ScreenUpdating = True
Unload Me
End Sub


But how do I check if the value of the bookmark is empty or not? And how do I show it in a textbox on a form? :dunno

Help please

Killian
04-26-2006, 01:44 AM
Hi Rico,

You could use the document open event to check for the bookmark value first and second form's "Initialize" populate the text box the textboxPrivate Sub Document_Open()
If Len(ActiveDocument.Bookmarks("MyBookmark").Range.Text) = 0 Then
'show “insert value” form
Else
'show “do you want to change value” form
End If
End Sub

'########

Private Sub UserForm_Initialize()
txtMyTextbox.Value = ActiveDocument.Bookmarks("MyBookmark").Range.Text
End Sub

Rico
04-26-2006, 12:20 PM
Hi Killian

Thanks a lot I will try it at once :thumb

Regards Rico