Subform lost focus code doesnt prompt user

Well it's up to you when you want the validation to kick in. If you want it to happen when you step out of the control then it will be the control's Before Update event, however, if you want it to fire when you attempt to save the entire record then it will be the form's Before Update event.
 
This is your project and of course you should do what you think is best, but (there's always a but after a statement like that) validation in the Forms Before Update event will prevent records from being saved with a Null value. Validation in the Controls Before Update or the controls Lost focus events may not. The first only fires if there is some change. The second only fires if it is entered first.
 
Sorry to open this one again... Im trying to set focus on the subform control if the control is blank.

As I understand it from reading various posts you have to add 2 entries - 1 to take you to the subform and then the second to take you to the control as per -

Code:
If Nz(Forms![MainForm]![Subform].Form![Cost Code].Value, "") = "" Then
MsgBox "Please enter a cost code"
Me.MainForm.Subform.SetFocus
Me.MainForm.Subform.[Cost Code].SetFocus
End If
End Sub

Im trying to understand how to relate to the different forms from the main form as per http://access.mvps.org/access/forms/frm0031.htm

So its not that Im not trying - Im just thick :banghead:
 
Try:
Code:
If Nz(Forms![MainForm]![Subform].Form![Cost Code].Value, "") = "" Then
MsgBox "Please enter a cost code"
Me.MainForm.Subform.Form.SetFocus
Me.MainForm.Subform.Form.[Cost Code].SetFocus
End If
End Sub
 
If you're checking that a field is blank in the subform, then you should be performing this check in the subform itself, not the parent form.
 

Users who are viewing this thread

Back
Top Bottom