Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2017, 03:23 PM
Pindar Pindar is offline Macro to autofill a form field ONLY if the form field is blank upon entry Windows 7 64bit Macro to autofill a form field ONLY if the form field is blank upon entry Office 2010 64bit
Novice
Macro to autofill a form field ONLY if the form field is blank upon entry
 
Join Date: Jan 2017
Posts: 12
Pindar is on a distinguished road
Default 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

Reply With Quote
  #2  
Old 01-12-2017, 04:32 PM
macropod's Avatar
macropod macropod is offline Macro to autofill a form field ONLY if the form field is blank upon entry Windows 7 64bit Macro to autofill a form field ONLY if the form field is blank upon entry Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

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]
Reply With Quote
  #3  
Old 01-12-2017, 05:03 PM
Pindar Pindar is offline Macro to autofill a form field ONLY if the form field is blank upon entry Windows 7 64bit Macro to autofill a form field ONLY if the form field is blank upon entry Office 2010 64bit
Novice
Macro to autofill a form field ONLY if the form field is blank upon entry
 
Join Date: Jan 2017
Posts: 12
Pindar is on a distinguished road
Default

Perfect, thank you.
Reply With Quote
Reply



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
Macro to autofill a form field ONLY if the form field is blank upon entry Form field selection allows entry into form text box David C Word 1 10-24-2012 04:53 AM
Macro to autofill a form field ONLY if the form field is blank upon entry 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
Macro to autofill a form field ONLY if the form field is blank upon entry Word Macro That Checks a Check Box Form Field When File Print is Executed DKerne Word VBA 4 06-09-2011 11:54 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:02 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