Form & Subform Closing w/Completion Check
Hi,
I've been working on a simple database to record and track status of requests for files. I'm currently working on a form (frmManageRequests) and 2 subforms where a user would add actions (sfrmAddNewActions) that show movement of an existing file request and any history of prior actions (sfrmViewActions)
The main form opens to show only 1 request at a time based on a selection from a list on another form.
I do not allow fields on the main form to be updated or any on the subform that shows the history. There are three fields on the sfrmAddNewActions which can be updated-- Action_Type, ActionInitiator and Volumes. I am trying to require data entry for the first two, third is optional. I allow a cancel/delete with a button on the record level of the subform since I don't let users revise history. Upon close from a main form button, I need to check for required data entry for the first two fields in the subform without eliminating the possibility that someone may want to close the form without entering anything in any fields (ie decide not to add an action at all).
I am using the following code on the main form close button.
Private Sub cmdSaveandCloseManageRequests_Click()
On Error GoTo Err_cmdSaveandCloseManageRequests_Click
If IsNull(Form!sfrmAddNewActions!Action_Type) Then
MsgBox "Please Select the Action Taken"
ElseIf IsNull(Form!sfrmAddNewActions!ActionInitiator) Then
MsgBox "Please Select the Initiator"
Else
DoCmd.Save
DoCmd.Close
End If
Exit_cmdSaveandCloseManageRequests_Click:
Exit Sub
Err_cmdSaveandCloseManageRequests_Click:
MsgBox Err.Description
Resume Exit_cmdSaveandCloseManageRequests_Click
End Sub
The above works beautifully for the required data entry check but when I add in a bit to handle the situation where a user may close w/out adding an "action" I begin to have problems.
If IsNull(Form!sfrmAddNewActions!Action_Type And Form!sfrmAddNewActions!ActionInitiator And Form!sfrmAddNewActions!Volumes) Then
DoCmd.Close
ElseIf IsNull(Form!sfrmAddNewActions!Action_Type) Then
MsgBox "Please Select the Action Taken"
ElseIf IsNull(Form!sfrmAddNewActions!ActionInitiator) Then
MsgBox "Please Select the Initiator"
Else
DoCmd.Save
DoCmd.Close
End If
The code allows a nice main form close if all is null but as soon as I test by adding one required field and leaving the second blank, I get an error from access that says "type mismatch" . I've only ever seen type mismatch when I write queries (text and number mismatch), I confess I'm stumped as to why the problem crops up so suddenly here when the data entry check worked fine independent of adding the all fields null check before it. I hope it is a silly mistake on my part :) Any ideas about where I've gone wrong? Thank you for any assistance!
|