How to make a subform field mandatory?

vid

Registered User.
Local time
Today, 03:56
Joined
Feb 4, 2010
Messages
62
Hi!

I have a subform with a field called Reason Code, which i want to make mandatory.

I know 2 ways to do so:

The simplest one was to make the field in the table as required. This works perfectly, but the problem is that message box that is displayed when the field is left empty. It says something like " you must fill in Warranty claim details.Reason Code". So it look very unprofessional.

The other way was to use VBA. I found something online which basically used the beforeupdate property of the save button which is on the main form. The problem is that the code can be used for a field on the main form but for the sunform case it doesnt work.

the code was something like this:

Dim strMText As String
Dim strMTitle As String
Dim intMType As Integer

If IsNull(Me.YourControl) Then

strMText = "Please complete the "
If IsNull(Me.YourControl) Then
strMText = "YourControl"
Me.YourControlName.SetFocus

End If

strMTitle = "Missing required information"
intMType = vbOKOnly + vbCancel + vbExclamation
MsgBox strMText, intMType, strMTitle

Else
DoCmd.Close
End If

could you tell me either how to edit this code or another way..

Please Help!
 
Check (and bookmark) this link for the correct syntax for referring to forms/subforms and their controls.

Try replacing;
Code:
If IsNull(Me.YourControl) Then
with;
Code:
If IsNull(Me!Subform1.Form!ControlName) Then

You will of course also need to make the appropriate changes to all other references to Me.YourControl.
 
Hey!

Yeah this is working now. But I'm facing another problem..

My subform is like a table so it has many entries, each row is a different entry. this code only seems to show the error when the reason code for the last row i fill in is left blank. otherwise it allows the system to save!

Any suggestions???!!
 
You could try putting the code in the field in question's On Lost Focus event. That assumes of course that your user does not use his mouse to by pass that field all together.
 
You could try putting the code in the field in question's On Lost Focus event. That assumes of course that your user does not use his mouse to by pass that field all together.
 
Thanks for the help! I'll try it out :)
 

Users who are viewing this thread

Back
Top Bottom