View Single Post
 
Old 05-01-2014, 05:26 PM
alshcover alshcover is offline Windows 7 64bit Office 2010 64bit
Novice
 
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