|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Macro to autofill a form field ONLY if the form field is blank upon entry
Hello, I'm new to writing macros. I'm trying to make a form that auto-fills the current date in a form field, but allows you to edit the date afterward, and I don't want it to change any date that is already in the box. Below is the macro I'm using so far. It adds the date successfully, but I don't want it to run if there is already a date in the box. What should I add?
Code:
Sub SetDate() Dim sDate As Date sDate = Format((Now), "MM/dd/yyyy") ActiveDocument.FormFields("Text1").Result = sDate End Sub |
#2
|
||||
|
||||
Try:
Code:
Sub SetDate() With ActiveDocument.FormFields("Text1") If .Result = "" Then .Result = Format((Now), "MM/dd/yyyy") End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Perfect, thank you.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
MACRO - Insert row based on Form Field Criteria | Elan05 | Word VBA | 5 | 04-16-2013 06:39 AM |
Form field selection allows entry into form text box | David C | Word | 1 | 10-24-2012 04:53 AM |
Form Fields - Create blank form text field with if statement? | LAssist2011 | Word | 5 | 12-14-2011 03:02 PM |
Macro to populate a text form field based on dropdown selection | koloa | Word | 0 | 10-20-2011 11:52 AM |
Word Macro That Checks a Check Box Form Field When File Print is Executed | DKerne | Word VBA | 4 | 06-09-2011 11:54 AM |