Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2019, 04:54 PM
Gogosaur Gogosaur is offline When check box is selected, need text to be written on bookmark Windows 7 64bit When check box is selected, need text to be written on bookmark Office 2016
Novice
When check box is selected, need text to be written on bookmark
 
Join Date: Jan 2019
Posts: 2
Gogosaur is on a distinguished road
Default When check box is selected, need text to be written on bookmark

I'm trying to create a form so that when users click a checkbox to request a certain document, a string of text will display in a bookmark on a word doc.



I have a checkbox named cbIEP that when checked, I want it to display "Request IEP" in the bookmark bmIEP.

Another checkbox named cbPsy that when checked, I want it to display "Request Psych Eval" in the bookmark bmPsy.

Thank you in advance
Attached Files
File Type: docm help.docm (25.6 KB, 25 views)

Last edited by Gogosaur; 01-25-2019 at 11:44 AM.
Reply With Quote
  #2  
Old 01-24-2019, 09:42 PM
Guessed's Avatar
Guessed Guessed is offline When check box is selected, need text to be written on bookmark Windows 10 When check box is selected, need text to be written on bookmark Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Actually your checkboxes are named chckIEP and chckPsy

I would address this by adding the bookmark name and text values to the tag and ControlTipText properties on the relevant userform checkboxes. Then you implement the following code changes to the userform code - amend OK_Click and add the PopulateBM function.
Code:
Private Sub OK_Click()
  Application.ScreenUpdating = False
  With ActiveDocument
     .Bookmarks("bmDate").Range.Text = txtDate.Value
     .Bookmarks("bmName").Range.Text = txtName.Value
     .Bookmarks("bmUCI").Range.Text = txtUCI.Value
     .Bookmarks("bmDOB").Range.Text = txtDOB.Value
     .Bookmarks("bmSchool").Range.Text = txtSchool.Value
     .Bookmarks("bmIEPY").Range.Text = txtIEPY.Value
     .Bookmarks("bmPsyY").Range.Text = txtPsyY.Value
     .Bookmarks("bmSC").Range.Text = txtSC.Value
    PopulateBM Me.chckIEP
    PopulateBM Me.chckPsy
  End With
  Application.ScreenUpdating = True
  Unload Me
End Sub

Function PopulateBM(aCtl As Control)
  Dim sBkmk As String, sText As String
  sBkmk = aCtl.Tag
  sText = aCtl.ControlTipText
  With ActiveDocument
    If .Bookmarks.Exists(sBkmk) Then
      If aCtl Then
        .Bookmarks(sBkmk).Range.Text = sText
      Else
        .Bookmarks(sBkmk).Range.Text = ""
      End If
    End If
  End With
End Function
Attached Images
File Type: png TagIt.png (20.7 KB, 40 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 01-24-2019, 10:01 PM
gmayor's Avatar
gmayor gmayor is offline When check box is selected, need text to be written on bookmark Windows 10 When check box is selected, need text to be written on bookmark Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
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

Another way is to use the following macro to write your values to the bookmarks
You can then call it from your form e.g.
Code:
FillBM "bmDate", txtDate.Value
FillBM "bmName", txtName.Value
This ensures that the text is written IN the bookmark rather than AT it, thus enabling the values to be recalled to the userform should you wish to recall the userform to edit the document.
For optional insertions
Code:
If chckIEP.Value = True Then
    FillBM "bmIEP", "Request IEP"
Else
    FillBM "bmIEP", ""
End If
Code:
Public Sub FillBM(strbmName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim orng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set orng = .Bookmarks(strbmName).Range
        orng.Text = strValue
        orng.Bookmarks.Add strbmName
    End With
lbl_Exit:
    Set orng = Nothing
    Exit Sub
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
  #4  
Old 01-24-2019, 11:06 PM
Guessed's Avatar
Guessed Guessed is offline When check box is selected, need text to be written on bookmark Windows 10 When check box is selected, need text to be written on bookmark Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Graham is correct about the bookmark position not 'including' the text so you couldn't revisit the dialog multiple times. To resolve this on my previous code, the function should be amended to...
Code:
Function PopulateBM(aCtl As Control)
  Dim sBkmk As String, sText As String, aRng As Range
  sBkmk = aCtl.Tag
  sText = aCtl.ControlTipText
  With ActiveDocument
    If .Bookmarks.Exists(sBkmk) Then
      Set aRng = .Bookmarks(sBkmk).Range
      If aCtl Then
        aRng.Text = sText
      Else
        aRng.Text = ""
      End If
      aRng.Bookmarks.Add sBkmk
    End If
  End With
End Function
You could then query the values in those bookmarks to prefill the status of both settings as part of the UserForm_Initialize macro.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 01-25-2019, 05:35 AM
gmayor's Avatar
gmayor gmayor is offline When check box is selected, need text to be written on bookmark Windows 10 When check box is selected, need text to be written on bookmark Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
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

While bookmarks are all very well and will certainly do the job, as both Andrew and I have indicated, I would suggest that you consider using content controls instead s they are more robust and harder for users to delete accidentally. I have modified some of your template to use controls. You can fill the rest yourself.

You don't need the date. Use a createdate field instead. Nor do you need the Clear button as this should be a template from which you create new documents.


As you have a combo box for the districts, make that a multiple column combo box and use the extra columns for the address parts.


It would be poissible to store the Districts and addresses in Excel and read them into the userform. You can find out how to do that from my web site.
Attached Files
File Type: dotm help-2.dotm (44.3 KB, 42 views)
__________________
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
  #6  
Old 01-25-2019, 03:01 PM
Gogosaur Gogosaur is offline When check box is selected, need text to be written on bookmark Windows 7 64bit When check box is selected, need text to be written on bookmark Office 2016
Novice
When check box is selected, need text to be written on bookmark
 
Join Date: Jan 2019
Posts: 2
Gogosaur is on a distinguished road
Default

Thank you. I was able to manipulate the form with content control to do what I want but I'm still lost on how to get my original form to work.

I amended OK_Click, added the function and added my bookmark to the checkbox tag but I don't quite understand where I'm suppose to add the code to tell the form what I want it to say. Learning from scratch and it's bugging me not knowing where to go from there.
Reply With Quote
  #7  
Old 01-25-2019, 10:24 PM
gmayor's Avatar
gmayor gmayor is offline When check box is selected, need text to be written on bookmark Windows 10 When check box is selected, need text to be written on bookmark Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
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

See http://www.gmayor.com/Userform.htm
__________________
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Any efficient way to lock text that’s always written in a certain format? Gilvv Word 25 11-25-2018 04:52 PM
Macro to insert different sets of text at bookmark depending on sequence of selected check boxes chipper09 Word VBA 0 06-21-2018 01:49 PM
When check box is selected, need text to be written on bookmark Moving Selected Items from a Multiselect Listbox on a userform to a bookmark in Word marksm33 Word VBA 3 01-15-2015 07:55 PM
When check box is selected, need text to be written on bookmark Getting mult resps. selected in listbox to concatenate & paste at a bookmark in Word marksm33 Word VBA 3 01-15-2015 05:59 PM
Animation: text appears as if written by pen ionas.iona PowerPoint 0 03-31-2011 05:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:01 AM.


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