Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-31-2021, 09:05 PM
Javi78503 Javi78503 is offline Generate a string only if textbox has been changed Windows 10 Generate a string only if textbox has been changed Office 2019
Novice
Generate a string only if textbox has been changed
 
Join Date: Jul 2021
Posts: 14
Javi78503 is on a distinguished road
Default Generate a string only if textbox has been changed

So I am trying to build a vba code to only generate a string of data concactenated from various textboxes if the initial box has been edited.

For context I'm trying to list schedules for an unknown # of people. I have a User form i'm piggybacking off of for fields that include: Person name, days attending, and hours. I have these boxes for up to 10 people currently and my end goal is to generate a line in my word document at a specific bookmark only if Person Name field textbox on the userform has been changed.

My fields on the userform read as:
PNBox
DABox
HABox
1PNBox
1DABox
1HABox
...
all the way to 10

assuming i fill in the info for the first two people the following two lines would generate

John Doe, Mon- Fri, 8:00am - 5:00pm


Jane Doe, Mon- Thu, 8:00am - 5:00pm

however, here's where i'm having the issue... I want to use the Bookmarks.Add method and only want it to generate the bookmarks for days and hours IF the name field has been changed. I hope i've explained that well enough. Cause otherwise I have a section in my document that is just , , , , where I have the bookmarks built in around the commas

I'm a total noob at VBA but i've managed to complete all other things i'm trying to do, it's this bit of code I can't seem to pull together.

This is all i've got, please don't laugh :P

Code:
Dim Temp As Range
If ActiveDocument.Bookmarks.Exists("bmPN") Then
If Me.PNBox.Value <> “Persons Name” Then
ActiveDocument.Bookmarks("bmPN").Range.InsertAfter _
  ", "
ActiveDocument.Bookmarks.Add Name:="bmDA
ActiveDocument.Bookmarks("bmDA").Range.InsertAfter _
  ", "
ActiveDocument.Bookmarks.Add Name:="bmHA
Set Temp = ActiveDocument.Bookmarks("bmPN").Range
Temp.Text = Me.PNBox.Value
End If
End If
after that I have the code to change the other bookmarks if they exist, and i've got that part down

...Help
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate a string only if textbox has been changed Wildcard replace any string in context with a specified string wardw Word 7 05-07-2018 09:13 AM
Generate a string only if textbox has been changed How can I compare a string in a cell to another string? Amitti Word VBA 2 04-10-2017 07:35 PM
How to find all string within string. PRA007 Word VBA 18 02-12-2016 08:11 PM
Generate a string only if textbox has been changed Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
Generate a string only if textbox has been changed Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM

Other Forums: Access Forums

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