Multiple Field Criteria

johnsqftwr

Registered User.
Local time
Today, 00:47
Joined
Jul 19, 2004
Messages
29
Hi All,

I have a form with 2 Memo Fields. CallReasonComments and HowResolved.

TheCallReasonComments must always be completed and the HowResolved must be filled in if the Resolved Check Box is ticked.

I have searched the threads and the form before update event is as follows:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.CallReasonComments) Then
MsgBox "The Reason Must Be Expanded In The Comments Field", _
vbCritical, _
"Canceling Update"
Me.CallReasonComments.SetFocus
Cancel = True
End If

If Me.Resolved = -1 And IsNull(Me.HowResolved) Then
MsgBox "How Resolved Must Be Completed", _
vbCritical, _
"Canceling Update"
Me.HowResolved.SetFocus
Cancel = True
End If

End Sub

The form also has 2 Buttons.
Save And Go to new record (Macro) AND Close
If the buttons are clicked the following happens
Save And Go To new Record:
Action Failed (Trying to run macro) followed by 'You can't go to the specified record'
Close: Simply closes the form without any warning that the record hasn't been saved.

I would like to stop these button working if the before update criteria has not been complied with.

Any help greatly appreciated.

Regards
 
you could approach this another way, by enabling and disabling buttons based on what is or isn't filled in. you can use the On Current event and On Dirty event. On Dirty, disable the close button and enable the Save button, plus an Undo button.

the before update event can be tricky if you currently have empty fields that need to be filled in. if the record is viewed but nothing is typed, before update won't fire; it will only fire if entering or editing takes place. but On Current will fire, even when viewing.
 
Many thanks.

I will give this a try
 
I am totally lost here!

I have the following in the Dirty Event of the FORM
Private Sub Form_Dirty(Cancel As Integer)
If IsNull(Me.CallReasonComments) Then
Me.cmdNewRecord.Enabled = True
Me.cmdClose.Enabled = False
End If
End Sub

Could you help further?

many thanks
 
Do a search on "Validation" I think you'll see a few ways to do it... You might look into changing your validation criteria to a function, then call the function on close...
 
I am totally lost here!
I have the following in the Dirty Event of the FORM
Code:
Private Sub Form_Dirty(Cancel As Integer)
[COLOR=red]If IsNull(Me.CallReasonComments) Then[/COLOR]
Me.cmdNewRecord.Enabled = [COLOR=seagreen]False[/COLOR] [COLOR=red]'True[/COLOR]
Me.cmdClose.Enabled = False
[COLOR=seagreen]Me.cmdSave.Enabled = True[/COLOR]
[COLOR=seagreen]Me.cmdUndo.Enabled = True[/COLOR]
[COLOR=red]End If[/COLOR]
End Sub
- remove the If/End If lines above (in red); add the lines in green (need Undo button).
- do your testing with the Save button. if all is well enable/disable buttons appropriately and the user can move on or close.
 
Many thanks for your reply.

When I open the form now all buttons are enabled.
As soon as I start data entry, the New Record & Close Form buttons are disabled.

I am not sure where to go now. I assume I need something in the OnCurrent event with the criteria?

Code:
If IsNull(Me.CallReasonComents) Then etc....
Regards
 
--> do your testing with the Save button...
 
Sorry for late reply. Have been away. Many thanks for your help. Got there in the end.
 
Private Sub Form_Dirty(Cancel As Integer)
If IsNull(Me.CallReasonComments) Then
Me.cmdNewRecord.Enabled = False 'True
Me.cmdClose.Enabled = False
Me.cmdSave.Enabled = True
Me.cmdUndo.Enabled = True
End If
End Sub

is there a form dirty event?

even if there is, this CANT be the correct place to test

the correct place is the forms BEFOREUPDATE event, surely
 

Users who are viewing this thread

Back
Top Bottom