Hi,
I have a main/sub input form and have a close button that should check if a specific field has been entered on the sub form - if it is empty then the record is not saved.
I have the following existing code :
Control for the Close button
Empty Record Check Module
I've started getting the message that "the command or action'Undo' isn't available now
I can't see why this won't work - any help ?
I have a main/sub input form and have a close button that should check if a specific field has been entered on the sub form - if it is empty then the record is not saved.
I have the following existing code :
Control for the Close button
Code:
Private Sub btn_CloseForm_Click()
'------------------------------------------------------------
' CONTROL FOR CLOSE BUTTON
'------------------------------------------------------------
On Error GoTo btn_CloseForm_Click_Err
'Call the macro to check for empty records
Forms!frm_MainInput.SetFocus
EmptyRecordCheck
btn_CloseForm_Click_Exit:
Exit Sub
btn_CloseForm_Click_Err:
MsgBox Error$
Resume btn_CloseForm_Click_Exit
End Sub
Empty Record Check Module
Code:
Function EmptyRecordCheck()
'------------------------------------------------------------
' Don't Save Empty Records
' If there is no Project Number and the form is closed then record will not save
'------------------------------------------------------------
On Error GoTo EmptyRecordCheck_Err
'Check if the subform field "ProjectCode" is empty when the MainInput form is closed
If (IsNull(Forms!frm_MainInput!frm_subRowDetail.Form!FormProjectCode)) Then
'Then do not save a record (undo)
DoCmd.RunCommand acCmdUndo
Beep
MsgBox "No Project Code entered - this record will not be saved", vbOKOnly, "Empty Record"
End If
'Close the form
DoCmd.Close , ""
EmptyRecordCheck_Exit:
Exit Function
EmptyRecordCheck_Err:
If Err.Number <> 2501 Then
MsgBox Error$
End If
Resume EmptyRecordCheck_Exit
End Function
I've started getting the message that "the command or action'Undo' isn't available now
I can't see why this won't work - any help ?