Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-09-2013, 06:53 AM
thedeadzeds thedeadzeds is offline Mandatory field in a form Windows XP Mandatory field in a form Office 2003
Novice
Mandatory field in a form
 
Join Date: May 2013
Posts: 5
thedeadzeds is on a distinguished road
Default Mandatory field in a form


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
Attached Files
File Type: doc JOTTER.doc (100.0 KB, 15 views)
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mandatory field in a form Form field selection allows entry into form text box David C Word 1 10-24-2012 04:53 AM
Mandatory field in a form Can't tab from field to field in form Lynieee Word 6 06-18-2012 02:37 PM
Word form field JBaker Word 18 03-22-2012 09:05 AM
Mandatory field in a form Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM
Form Field Shading. Ninerhoss Word 0 11-23-2010 02:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft