Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 07-30-2014, 04:01 AM
Byron Polk Byron Polk is offline Compare text from Bookmark with text from Text box Windows 7 64bit Compare text from Bookmark with text from Text box Office 2010 32bit
Novice
Compare text from Bookmark with text from Text box
 
Join Date: Jul 2014
Location: Whitehouse, TX
Posts: 14
Byron Polk is on a distinguished road
Default

macropod,

Thanks for your response.

I going to attach a document that will demo what code I am using to read the values. In this document I have created the bookmark and text box manually and am only reading and attempting to compare the values through code. I was not able to upload the .docm docment. so here is the code from Macro1:

Code:
Dim shp As Shape
Dim strKeyInfo As String
Dim strText As String
 strKeyInfo = ActiveDocument.Bookmarks("Record").Range.Text
 For Each shp In ActiveDocument.Shapes
    If shp.Type = msoTextBox Then
        shp.Select
        strText = shp.TextFrame.TextRange.Text
        If strKeyInfo = strText Then
            MsgBox "Values Match!"
        Else
            MsgBox "Values Do Not Match!"
        End If
    End If
Next shp
I my actual project, I have an existing bookmark and I have a userform where the user is prompted to provide the information that is to be programatically used to update the text at the bookmark. In the actual project I am creating the text box and populating the text based on user selections from the same userform.

Below is the code that I am using to update the bookmark:

Code:
Dim strKey As String
strChar1 = Me.cboKeyList
If Me.cboKeyModifier > "" Then
    strChar2 = Me.cboKeyModifier
Else
    strChar2 = ""
End If
strChar3 = Me.cboMajMin
strKey = strChar1 & strChar2 & " " & strChar3
UpdateBookmark "Key", strKey
This code calls the "UpdateBookmark" function:
Code:
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
    Dim BMRange As Range
    Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
    BMRange.Text = TextToUse
    ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
Later on I use the code below to acquire the text from the bookmark
Code:
strKeyInfo = ActiveDocument.Bookmarks("Key").Range.Text
If CheckForDesignatedKey(strKeyInfo) = False Then
This code calls the "CheckForDesignatedKey" function below to read the text from the text box and attempt to compare that value with the valaue from the bookmark

Code:
Public Function CheckForDesignatedKey(sKeyToFind As String) As Boolean
'returns true if key is found in any textbox
Dim shp As Shape, strText As String
CheckForDesignatedKey = False
For Each shp In ActiveDocument.Shapes
    If shp.Type = msoTextBox Then
        shp.Select
        strText = shp.TextFrame.TextRange.Text
        If sKeyToFind = strText Then
            CheckForDesignatedKey = True
        End If
    End If
Next shp
 End Function
For what it is worth, the bookmark is located in the document header, but that does not seem to have any thing to do with the issue.

When I run my code and display the returned values from my variables in the immediate code window they both appear to have exactly the same values. I keep thinking that I am just missing something.

I appreciate your attempting to help.

Please take a look at the attached document and the code in Macro1. Hopefully you will see where the problem is.

Byron
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare text from Bookmark with text from Text box VBA to input / clear text from a Bookmark micko1 Word VBA 10 11-05-2013 04:42 PM
Compare text from Bookmark with text from Text box Open header to insert text into bookmark Amapola188 Word VBA 3 07-12-2012 05:16 PM
Repeating Bookmark Text BECKTHOMO Word 1 03-27-2012 08:34 PM
Compare text from Bookmark with text from Text box Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM
Compare text from Bookmark with text from Text box delete all bookmark text hklein Word VBA 4 08-10-2011 04:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:30 PM.


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