Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2022, 05:54 AM
TheBigBoss TheBigBoss is offline With macro/userform to replace bookmark only works with number Windows 7 32bit With macro/userform to replace bookmark only works with number Office 2010 32bit
Advanced Beginner
With macro/userform to replace bookmark only works with number
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default With macro/userform to replace bookmark only works with number

Hi there,

This simple userform replacing bookmarks works fine but only with numbers...
... and yet all functions, all variables are string ??


If you type any letter or special character, MS Words doesn't even accept the input. Nothing is happening.

What did I miss here? So strange...
Attached Files
File Type: dotm Why.dotm (35.9 KB, 11 views)
Reply With Quote
  #2  
Old 03-27-2022, 08:28 PM
gmayor's Avatar
gmayor gmayor is offline With macro/userform to replace bookmark only works with number Windows 10 With macro/userform to replace bookmark only works with number Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Change the userform code to
Code:
Option Explicit


Private Sub CommandButton1_Click()
    Dim tmp As String
   
    If TextBox1.Text <> "" And TextBox1.Text <> TextBox1Before.Text Then
       WriteBk2 "TextBox1", TextBox1.Text
       TextBox1Before.Text = TextBox1.Text
    End If
    
    If TextBox2.Text <> "" And TextBox2.Text <> TextBox2Before.Text Then
       WriteBk2 "TextBox2", TextBox2.Text
       TextBox2Before.Text = TextBox2.Text
    End If
    
    If TextBox3.Text <> "" And TextBox3.Text <> TextBox3Before.Text Then
       WriteBk2 "TextBox3", TextBox3.Text
       TextBox3Before.Text = TextBox3.Text
    End If



    Unload Me
End Sub

Private Sub UserForm_Initialize()
        Dim tmp As String
       
        tmp = ReadBk("TextBox1")
        TextBox1.Text = tmp
        TextBox1Before.Text = tmp
        
        tmp = ReadBk("TextBox2")
        TextBox2.Text = tmp
        TextBox2Before.Text = tmp
        
        tmp = ReadBk("TextBox3")
        TextBox3.Text = tmp
        TextBox3Before.Text = tmp            
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-27-2022, 10:26 PM
TheBigBoss TheBigBoss is offline With macro/userform to replace bookmark only works with number Windows 7 32bit With macro/userform to replace bookmark only works with number Office 2010 32bit
Advanced Beginner
With macro/userform to replace bookmark only works with number
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

Thank you very much Graham, it works.
Text and Value are not the same
Quote:
The Text property returns the formatted string. The Text property may be different than the Value property for a text box control. The Text property is the current contents of the control. The Value property is the saved value of the text box control. The Text property is always current while the control has the focus.

The Value property returns or sets a control's default property, which is the property that is assumed when you don't explicitly specify a property name.
TextBox.Value property (Access) | Microsoft Docs
For the record, I had to change the userform slightly for the macros to work.
TextBox = True is replaced with TextBox <> ""
Code:
Option Explicit

Private Sub CommandButton1_Click()
    Dim tmp As String
   
   Debug.Print TextBox1Before.Text
    If TextBox1.Text <> "" And TextBox1.Text <> TextBox1Before.Text Then
        Debug.Print TextBox1.Text
       WriteBk2 "TextBox1", TextBox1.Text
       TextBox1Before.Text = TextBox1.Text
    End If
    
    If TextBox2.Text <> "" And TextBox2.Text <> TextBox2Before.Text Then
       WriteBk2 "TextBox2", TextBox2.Text
       TextBox2Before.Text = TextBox2.Text
    End If
    
    If TextBox3.Text <> "" And TextBox3.Text <> TextBox3Before.Text Then
       WriteBk2 "TextBox3", TextBox3.Text
       TextBox3Before.Text = TextBox3.Text
    End If
    
    Unload Me

End Sub


Private Sub UserForm_Initialize()
        Dim tmp As String
       
        tmp = ReadBk("TextBox1")
        TextBox1.Text = tmp
        TextBox1Before.Text = tmp
        
        tmp = ReadBk("TextBox2")
        TextBox2.Text = tmp
        TextBox2Before.Text = tmp
        
        tmp = ReadBk("TextBox3")
        TextBox3.Text = tmp
        TextBox3Before.Text = tmp
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
With macro/userform to replace bookmark only works with number Insert a picture from userform into bookmark in word document dyb Word VBA 5 02-18-2022 07:22 AM
With macro/userform to replace bookmark only works with number Delete lines with just a number on them - use macro or find & replace? enso Word 2 05-20-2019 02:58 AM
With macro/userform to replace bookmark only works with number Macro to Find and Replace Does Not Work - But Works Manually Rod_Bowyer Excel Programming 7 10-14-2018 11:49 PM
Userform without inserting Bookmark text mktate Word VBA 8 12-31-2015 01:11 PM
Send Userform Text to Bookmark tddfs Word VBA 5 07-30-2015 05:55 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:17 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