![]() |
#1
|
|||
|
|||
![]()
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 Last edited by Gogosaur; 01-25-2019 at 11:44 AM. |
#2
|
||||
|
||||
![]()
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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
![]()
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 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 |
#4
|
||||
|
||||
![]()
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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
![]()
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.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#6
|
|||
|
|||
![]()
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. |
#7
|
||||
|
||||
![]()
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
|
![]() |
||||
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 |
![]() |
marksm33 | Word VBA | 3 | 01-15-2015 07:55 PM |
![]() |
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 |