Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Newbie Question about clearing bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
robandcurtis@gmail.com - 17 Mar 2006 19:07 GMT
Work on my first form is progressing nicely, and I am almost ready to
start using it. One thing I have not been able to figure out is,
although I can reset the fields in the UserForm, I have been
unsuccessful at clearing the data placed in the bookmarks. I could just
open and close the form each time, but a reset button seemed a bit more
elegant. Is what I want to do possible?

Thanks

Private Sub CommandButton3_Click()
Dim ctrl As Control
For Each ctrl In Controls
   If TypeOf ctrl Is ComboBox Then ctrl.ListIndex = 0
   If TypeOf ctrl Is TextBox Then ctrl.Text = ""
Next ctrl

End Sub

Private Sub UserForm_Initialize()

With Me.ComboBox1
   .AddItem "Select your signature"
   .AddItem "Rob Jesson"
   .AddItem "James Lefave"
   .AddItem "Dan Craig"
   .AddItem "Greg Martin"
   .AddItem "Jason Kimmerly"
   .ListIndex = 0
End With

With Me.ComboBox2
   .AddItem "Add WLM Request Notification Sent"
   .AddItem "***Note: A request for Infomed Access has been forwarded
to Workload Measuerment"
   .AddItem "***Note: A request for WinPfs Access has been forwarded
to Workload Measuerment"
   .AddItem "***Note: A request for GRASP Access has been forwarded to
Workload Measuerment"
   .AddItem "***Note: A request for TREAT Access has been forwarded to
Workload Measuerment"
   .ListIndex = 0
   End With

   With Me.ComboBox3
   .AddItem "Add S:Drive Request Notification Sent"
   .AddItem "***Note: A request for S: Drive access has been forwarded
to the Folder Owners for:"
   .ListIndex = 0
   End With

End Sub

Private Sub CommandButton1_Click()
With Me.ComboBox1
   If .ListIndex = 0 Then
       MsgBox "You must select a signature."
       .SetFocus
       .SelStart = 0
       .SelLength = Len(.Text)
       Exit Sub
   Else
       ActiveDocument.Bookmarks("SigPlace").Range _
           .InsertAfter .Text
   End If
End With
With Me.ComboBox2
 ActiveDocument.Bookmarks("WLM").Range _
           .InsertAfter .Text
   End With

   With Me.ComboBox3
 ActiveDocument.Bookmarks("SDRIVE").Range _
           .InsertAfter .Text
   End With

With ActiveDocument
   .Bookmarks("FirstName").Range _
   .InsertBefore TextBox1
   .Bookmarks("LastName").Range _
   .InsertBefore TextBox2
   .Bookmarks("LoginID").Range _
   .InsertBefore TextBox3
   .Bookmarks("GWLogin").Range _
   .InsertBefore TextBox3
   .Bookmarks("Password").Range _
   .InsertBefore TextBox4
   .Bookmarks("GWPass").Range _
   .InsertBefore TextBox4
   .Bookmarks("Context").Range _
   .InsertBefore TextBox5
   .Bookmarks("CLID_ID").Range _
   .InsertBefore TextBox3
   .Bookmarks("CLID_CONT").Range _
   .InsertBefore TextBox5
   .Bookmarks("Department").Range _
   .InsertBefore TextBox6
   .Bookmarks("PO").Range _
   .InsertBefore TextBox7
   .Bookmarks("GW_GROUPS").Range _
   .InsertBefore TextBox8
   .Bookmarks("SMTP_FN").Range _
   .InsertBefore TextBox1
   .Bookmarks("SMTP_LN").Range _
   .InsertBefore TextBox2
   .Bookmarks("GWWA").Range _
   .InsertBefore TextBox3
   .Bookmarks("GWAA_PASS").Range _
   .InsertBefore TextBox4
   .Bookmarks("DESKTOP_ID").Range _
   .InsertBefore TextBox3
   .Bookmarks("ADD_DIR").Range _
   .InsertBefore TextBox10
   .Bookmarks("LINX_ID").Range _
   .InsertBefore TextBox3
   .Bookmarks("LINX_PASS").Range _
   .InsertBefore TextBox4
   .Bookmarks("LINX_Position").Range _
   .InsertBefore TextBox11
   .Bookmarks("EMP_ID").Range _
   .InsertBefore TextBox12
   .Bookmarks("DOB").Range _
   .InsertBefore TextBox13
   .Bookmarks("S1").Range _
   .InsertBefore TextBox14
    Selection.WholeStory
    Selection.Copy

End With

End Sub

Private Sub CommandButton2_Click()
Application.Quit SaveChanges:=wdDoNotSaveChanges

End Sub
Jay Freedman - 17 Mar 2006 19:53 GMT
To answer literally, see
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm for how to
put text _inside_ a bookmark, replacing whatever text (if any) is already in
it.

More fundamentally, you shouldn't be re-using the same document multiple
times. Make a template containing the text, the bookmarks, and the userform
and code. Use an AutoNew macro in the template to display the userform when
you click File > New and choose the template. The userform fills in the
bookmarks, and you then print, save, or discard the one-use document. The
next time you need to fill in the form, start over at File > New.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Work on my first form is progressing nicely, and I am almost ready to
> start using it. One thing I have not been able to figure out is,
[quoted text clipped - 131 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.