Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2014, 05:26 PM
alshcover alshcover is offline Update Bookmarks from a Userform Windows 7 64bit Update Bookmarks from a Userform Office 2010 64bit
Novice
Update Bookmarks from a Userform
 
Join Date: Apr 2014
Posts: 9
alshcover is on a distinguished road
Default

My original two questions/threads were for two different UserForms, so I'd like to keep the codes separate only to simplify things because I'm not well versed in this field... yet.

I have a UserForm with one control (cboName).
cboName values = Bob, Cindy, Peter, Vanessa. Each person has a unique ID number (1, 2, 3, 4 respectively).

Therefore, I created StrOut variables (1, 2, 3, 4), which are associated with each cboName value.

The document has a bookmark titled "Name". The value for cboName is inserted at this bookmark.

The document has another bookmark titled "ID". I would like the StrOut variable for its associated cboName value to be inserted at this bookmark.

With your help, I've put together the code below. Is this the correct use of the StrOut variables and the Call UpdateBookmark?
Code:
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
Dim StrOut As String
Select Case cboName.Value
  Case "Bob": StrOut = "1"
  Case "Cindy": StrOut = "2"
  Case "Peter": StrOut = "3"
  Case "Vanessa": StrOut = "4"
End Select
Call UpdateBookmark("ID", StrOut)
With ActiveDocument
    .Bookmarks("Name").Range.Text = cboName.Value
End With
Application.ScreenUpdating = True
Unload Me
End Sub

Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng
With ActiveDocument
If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
End If
End With
Set BkMkRng = Nothing
End Sub

Reply With Quote
  #2  
Old 05-01-2014, 05:32 PM
macropod's Avatar
macropod macropod is offline Update Bookmarks from a Userform Windows 7 32bit Update Bookmarks from a Userform Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,523
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by alshcover View Post
The document has a bookmark titled "Name". The value for cboName is inserted at this bookmark.

The document has another bookmark titled "ID". I would like the StrOut variable for its associated cboName value to be inserted at this bookmark.

With your help, I've put together the code below. Is this the correct use of the StrOut variables and the Call UpdateBookmark?
You're still not updating the "Name" bookmark for 'cboName.Value' properly:
Code:
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
Dim StrOut As String
StrOut = cboName.Value
Call UpdateBookmark("Name", StrOut)
Select Case cboName.Value
  Case "Bob": StrOut = "1"
  Case "Cindy": StrOut = "2"
  Case "Peter": StrOut = "3"
  Case "Vanessa": StrOut = "4"
End Select
Call UpdateBookmark("ID", StrOut)
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-02-2014, 11:20 AM
alshcover alshcover is offline Update Bookmarks from a Userform Windows 7 64bit Update Bookmarks from a Userform Office 2010 64bit
Novice
Update Bookmarks from a Userform
 
Join Date: Apr 2014
Posts: 9
alshcover is on a distinguished road
Default

With the current code, the cboName.Value is being inserted at Bookmark "Name" as I wanted it to. What kind of possible errors will the current code create regarding the bookmark?

Last edited by macropod; 05-02-2014 at 02:32 PM. Reason: Deleted unnecessary quote of entire post replied to.
Reply With Quote
Reply

Tags
date, format, userform



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Bookmarks from a Userform Checkbox in Userform lukael Excel Programming 5 02-18-2014 05:20 AM
Userform Code not quite right - help please vbanovice Word VBA 1 09-29-2013 09:20 PM
Update Bookmarks from a Userform Help with a drop down in userform and variables leemoreau Word VBA 1 09-14-2013 06:01 AM
VBA code to update record in Access 2003 using Userform in Excel primmer3001 Excel Programming 0 08-29-2011 04:25 PM
Update Bookmarks from a Userform Update bookmarks and variables in document webharvest Word VBA 5 06-21-2011 03:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft