thedeadzeds
New member
- Joined
- Oct 25, 2011
- Messages
- 37
- Reaction score
- 0
- Points
- 0
- Excel Version(s)
- 2016
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
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
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
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