My form/subform represents a contract with multiple individual line items for amounts to be spent on different projects. The goal of this form is to add more line items to an existing contract. The main form displays the contract header information (for tblContract); the subform is for entering detail line items (for tblContract_Lines). The tables/forms are linked on Contract_Number. The main form information is not editable, the form opens with the focus on the subform. The subform is a continuous form, so that more than one line item can be added to the contract.
-I have a command button ("OK") to close the form. The command button is located on the subform.
-I have a before_update event on the subform itself (not the subform control of the main form) to validate fields.
-I have an after_update event on the subform itself (again not the subform control of the main form) to ask if the user wants to add another line item (the msgbox is fired if the user either tabs through all the controls and completes the data entry on a line, or if the user clicks OK to signal they're completed).
My problem is that if the before_update event results in a fail, it does not return the user to the form field. It basically goes back to the close command button and closes the form. Here's the code:
Thank you for any help.
-I have a command button ("OK") to close the form. The command button is located on the subform.
-I have a before_update event on the subform itself (not the subform control of the main form) to validate fields.
-I have an after_update event on the subform itself (again not the subform control of the main form) to ask if the user wants to add another line item (the msgbox is fired if the user either tabs through all the controls and completes the data entry on a line, or if the user clicks OK to signal they're completed).
My problem is that if the before_update event results in a fail, it does not return the user to the form field. It basically goes back to the close command button and closes the form. Here's the code:
Code:
Private Sub Close_Form_Button_Click()
DoCmd.Close acForm, "frmMod_Contract_Form"
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([Forms]![frmMod_Contract_Form]![sbfrmMod_Contract_Lines].[Form]![Project_Number]) Then
MsgBox "Please enter a Project Number."
[Forms]![frmMod_Contract_Form]![sbfrmMod_Contract_Lines].[Form]![Project_Number].SetFocus
Cancel = True
Exit Sub
End If
End Sub
Private Sub Form_AfterUpdate()
Dim intAnswer As Integer
intAnswer = MsgBox("Are you done entering contract modification lines?", _
vbQuestion + vbYesNo, "Contract Modification")
If intAnswer = vbYes Then
DoCmd.Close acForm, "frmMod_Contract_Form"
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
Me!Amount.SetFocus
End If
End Sub
Thank you for any help.