Subform Validation Code

G

Giem

Hey all,

I have a form named frmNewRepair which has a subform named fsubRepairDetail
and a "close" button named cmdFinish.
This subform (fsubRepairDetail) has several controls and another subform
inside it named fsubRepairComplaint.

fsubRepairComplaint is a continuous form that has a combo box and a delete
button for each record. It is linked to a table for a many to many
relationship between 2 other tables. Previously it did not have a delete
button, and I used a union query for the combo box dropdown list to make a
Null option in the list. The problem I had was managing the resulting null
records so they would get deleted. At any rate, the delete button works great
instead of the null union. Now the problem is that the validation code in
cmdFinish on the main form doesn't work anymore. It is supposed to ensure
that at least ONE record is in this subform before the form is closed. It
still works for the rest of the controls, just not this nested subform now.
It has the following code:

********************

Private Sub cmdFinish_Click()
On Error GoTo Err_cmdFinish_Click

If IsNull(Me!fsubRepairDetail!cmbProductId) Or
IsNull(Me!fsubRepairDetail!txtSerial) _
Or IsNull(Me!fsubRepairDetail!fmWarranty) _
Or
IsNull(Me!fsubRepairDetail.Form!fsubRepairComplaint.Form!cmbComplaintId) _
'This is the line that doesn't seem to work anymore
Or IsNull(Me!fsubRepairDetail!txtNotes) Then

If Me!fsubRepairDetail.Enabled Then

MsgBox "You must fill in all fields. If there are no notes,
enter 'None' into the Notes field." _
& vbCrLf & "If you wish to delete this repair, click 'Delete
Item'." & vbCrLf & _
"If you wish to cancel the RMA, click 'Delete RMA'.", _
vbExclamation + vbOKOnly + vbApplicationModal, "All Fields
Required"

On Error Resume Next 'Supresses error when
Warranty option box _
does
not lose focus when button is clicked
Screen.PreviousControl.SetFocus
GoTo Exit_cmdFinish_Click

End If

End If

DoCmd.Close

Exit_cmdFinish_Click:
Exit Sub

Err_cmdFinish_Click:
MsgBox Err.Description
Resume Exit_cmdFinish_Click

End Sub


********************


Any help is appreciated and thanks in advance :)
 
G

Giem

Anyone have any ideas on this?

I am wanting the code to check whether the subform has a record(s) or not.
Currently the code posted won't trigger the msgbox even if there are no
records in this continuous subform. I have also tried checking to see if the
recordset of this subform isnull() to no avail.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top