![]() |
#1
|
|||
|
|||
![]()
I have a form with a filed named "Date". When someone enters the date I would like a macro to determine if that date is after August 1, 2019. If it is, then a bookmark called "Hello" becomes visible. IF the date is August 1, 2019, or before, then that bookmark remains invisible.
I also have a field called "Type". It is a drop-down field with 4 choices "1,2,3,4,5". On opening the file, or after saving the file , the field randomly becomes 1,2,3 or 4. However, I still want to be able to choose 5 manually at any time. |
#2
|
||||
|
||||
![]()
Create a new paragraph style called "Bookmark_Hidden" and format its font as hidden. Apply it to the bookmark which should then be hidden.
Assuming that the 'fields' are content controls then set the date field to display a valid date and use the following code. The second macro will randomly select items 1 to 4 in your list box, and you can still select any other item in that list. Frankly I don't see the point of this. Why not just select the item required? See attached example (note that there are regional issues involved when comparing dates from content controls using this method). Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) With ContentControl If .ShowingPlaceholderText = False Then Select Case .Title Case Is = "Date" If IsDate(.Range.Text) = True Then If Format(.Range.Text, "yyyymmdd") > 20190801 Then ActiveDocument.Styles("Bookmark_Hidden").Font.Hidden = False Else ActiveDocument.Styles("Bookmark_Hidden").Font.Hidden = True End If Else MsgBox "Not a valid date!" End If Case Else End Select Else ActiveDocument.Styles("Bookmark_Hidden").Font.Hidden = True End If End With End Sub Private Sub Document_Open() Dim occ As ContentControl Dim i As Integer ActiveDocument.Styles("Bookmark_Hidden").Font.Hidden = True ActiveDocument.SelectContentControlsByTitle("Date").Item(1).Range.Text = "" Set occ = ActiveDocument.SelectContentControlsByTitle("Type").Item(1) occ.DropdownListEntries.Item(Int((5 * Rnd) + 2)).Select Set occ = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com Last edited by gmayor; 09-12-2019 at 02:56 AM. |
#3
|
||||
|
||||
![]() Quote:
How can you have "a drop-down field with 4 choices "1,2,3,4,5""? You've specified 5 choices. Whichever option you choose will remain chosen if you save the file that way, but all 5 options will still be available for selection next time the file is opened.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to filter between two dates in MS Query criteria when the dates are text ("20180903", etc.) | kingmb | Excel | 2 | 09-11-2018 01:08 AM |
X axis graph all dates when date column contains specific dates..possible ? | DBenz | Excel | 2 | 03-28-2018 04:59 AM |
Autofill dates - how can I get the same date and consecutive dates? | Exhale | Excel | 3 | 04-05-2016 03:11 AM |
![]() |
etobias | Word | 4 | 12-03-2015 01:36 PM |
![]() |
SomewhereinTX | Project | 3 | 12-20-2013 10:25 AM |