![]() |
#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. I have attached the document Kind regards Craig 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 |
#2
|
||||
|
||||
![]()
Please don't post the same question in multiple threads. Also, when posting code, please use the code tags. They're on the 'Go Advanced' tab.
This thread closed.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
David C | Word | 1 | 10-24-2012 04:53 AM |
![]() |
Lynieee | Word | 6 | 06-18-2012 02:37 PM |
Word form field | JBaker | Word | 18 | 03-22-2012 09:05 AM |
![]() |
LAssist2011 | Word | 5 | 12-14-2011 03:02 PM |
Form Field Shading. | Ninerhoss | Word | 0 | 11-23-2010 02:40 PM |