View Single Post
 
Old 07-31-2021, 09:05 PM
Javi78503 Javi78503 is offline Windows 10 Office 2019
Novice
 
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