I am trying to Loop through Subform and Test two fields

bconner

Registered User.
Local time
Today, 13:25
Joined
Dec 22, 2008
Messages
183
I have an Access form with a Subform when the User clicks Save on the Main form I need to check and make sure a required field has been populated on the subform. Below is the code I am using it runs but doesn't work (ignores test). Basically if a User selects "Pending" in the cmb_ActionCode I want to require them to select a description from cmb_PendingDesc.


Code:
Forms![Frm_Main]![Tbl_Worklist_subform].SetFocus
If Not Forms![Frm_Main]![Tbl_Worklist_subform].Form.Recordset.EOF Then
     Forms![Frm_Main]![Tbl_Worklist_subform].Form.Recordset.MoveFirst
    For tmpint = 0 To Forms![Frm_Main]![Tbl_Worklist_subform].Form.Recordset.RecordCount - 1
       If (Forms!Frm_Main!Tbl_Worklist_subform![cmb_ActionCode] = "Pending" And IsNull(Forms!Frm_Main!Tbl_Worklist_subform![cmb_PendingDesc]) = True) Then
          MsgBox "When the Pending Action Code is selected you must select a Pending Description, Record Not Saved"
          Exit Sub
       End If
    Next tmpint
End If

Any help is greatly appreciated... thanks
 
Is there a reason you don't have this test in the subforms Before Update event?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.cmb_ActionCode = "Pending" And IsNull(Me.cmb_PendingDesc) Then
Cancel = 1
MsgBox "When the Pending Action Code is selected you must select a Pending Description, Record Not Saved"
End If
End Sub
 
I didn't even think of that! Thank you billmeye this was exactly what I was looking for.
 

Users who are viewing this thread

Back
Top Bottom