![]() |
#1
|
|||
|
|||
![]()
Hi Guys,
I have the follwoing code which works great as long as its used in 'Normal ThisDocument'. Any ideas how I get this to work in the 'Project Thisdocument' This VBA does not allow the user to save the form unless specifc fields in a word form have any entry. Kind regards Craig Code:
Option Explicit Private WithEvents oApp As Word.Application Private Sub Document_New() 'assign Word to the application variable If oApp Is Nothing Then Set oApp = ThisDocument.Application End If End Sub Private Sub Document_Open() 'assign Word to the application variable If oApp Is Nothing Then Set oApp = ThisDocument.Application End If End Sub Private Sub oApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean) If Doc.AttachedTemplate <> ThisDocument Then Exit Sub If Doc.FormFields("Text1").Result = "" Then Cancel = True MsgBox "An entry is required in the Customer Name field.", , "Error" Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="GoBacktoText1" Exit Sub End If If Doc.FormFields("Text2").Result = "" Then Cancel = True MsgBox "An entry is required in the DOB field.", , "Error" Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="GoBacktoText2" Exit Sub End If If Doc.FormFields("Text3").Result = "" Then Cancel = True MsgBox "An entry is required in the Work Number field.", , "Error" Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="GoBacktoText3" Exit Sub End If End Sub Sub GoBacktoText1() ActiveDocument.Bookmarks("Text1").Range.Fields(1). Result.Select End Sub Sub GoBacktoText2() ActiveDocument.Bookmarks("Text2").Range.Fields(1). Result.Select End Sub Sub GoBacktoText3() ActiveDocument.Bookmarks("Text3").Range.Fields(1). Result.Select End Sub Last edited by macropod; 05-09-2013 at 03:39 PM. Reason: Added code tags & formatting |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mandatory field in a form | thedeadzeds | Word | 1 | 05-09-2013 03:27 PM |
Merge field source data field | kckay | Mail Merge | 4 | 03-25-2013 11:06 AM |
Field not showing in Pivot Table Field List | kmcovington | Excel | 0 | 10-26-2012 10:14 AM |
Can I embed a Ref field in an If field in Word 2003? | skarden | Word | 2 | 01-05-2012 03:55 PM |
Formula to subtract one month from due date field in reminder field | ghumdinger | Outlook | 1 | 10-01-2011 12:09 AM |