Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2019, 06:55 AM
ElfegoBaca ElfegoBaca is offline Dates, Forms, Calculations etc. Windows 7 64bit Dates, Forms, Calculations etc. Office 2010 64bit
Novice
Dates, Forms, Calculations etc.
 
Join Date: May 2011
Posts: 5
ElfegoBaca is on a distinguished road
Default Dates, Forms, Calculations etc.

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.
Reply With Quote
  #2  
Old 09-11-2019, 10:46 PM
gmayor's Avatar
gmayor gmayor is offline Dates, Forms, Calculations etc. Windows 10 Dates, Forms, Calculations etc. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

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
Attached Files
File Type: docm CheckDate.docm (38.0 KB, 4 views)
__________________
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.
Reply With Quote
  #3  
Old 09-17-2019, 04:23 PM
macropod's Avatar
macropod macropod is offline Dates, Forms, Calculations etc. Windows 7 64bit Dates, Forms, Calculations etc. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by ElfegoBaca View Post
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.
Assuming you're working with formfields, see: https://www.msofficeforums.com/word/...-tutorial.html
Quote:
Originally Posted by ElfegoBaca View Post
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.
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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
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
Dates, Forms, Calculations etc. Calculations etobias Word 4 12-03-2015 01:36 PM
Dates, Forms, Calculations etc. Changing Actual Finish dates changes original Finish dates SomewhereinTX Project 3 12-20-2013 10:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft