Consulting

Results 1 to 20 of 81

Thread: How to change Date Picker content control format based on date comparison

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    How to change Date Picker content control format based on date comparison

    Good morning,

    I have two date picker content controls ("Visit Date - From" and "Visit Date -To") in a Word template. The template has been set up as a content type for a sharepoint library, so the two date fields are entered via the document information panel. I would like to change the format of the "Visit Date - From" depending on the dates entered in these two fields. The date format should appear as follows:

    • When the month in the 'from date' is different to the month in the 'to date', the format should be for example, 03 March - 12 April 2014, i.e. dd mmmm - dd mmmm yyyy.
    • When the same month appears in the 'from date' and the 'to date', the format should be for example, 03 - 08 March 2014, i.e. dd - dd mmmm yyyy.

    Both content controls in my word template are set to (dd mmmm yyyy).

    I thought I had cracked it by creating a calculated column in my sharepoint library using the formula:=IF(MONTH([Visit Date - From])=MONTH([Visit Date - To]),TEXT([Visit Date - From],"DD"),TEXT([Visit Date - From],"DD MMMM")) only to discover that you cannot insert calculated columns or values into a word document, at least not OOTB.

    Is it possible to achieve this through VBA?

    I managed to compare the two fields, but that's only when the same date appears in both fields (pretty feeble attempt I know).

    Sub SetDateFormat()
    
    If ActiveDocument.SelectContentControlsByTag("Visit_x0020_Date_x0020__x002d__x0020_From").Item(1).Range.Text = _
     ActiveDocument.SelectContentControlsByTag("Visit_x0020_Date_x0020__x002d__x0020_To").Item(1).Range.Text Then
     
    MsgBox "Match"
    End If
    End Sub
    Any pointers would be really appreciated.
    Last edited by JDS_916; 03-12-2014 at 03:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •