Cancel the changing to a different record in a subform

M

magicdds

I have a form with 2 subforms.

MainForm
Subform1
Subform2

Subform1 is linked to MainForm
Subform2 is linked to Subform1

When you click on a record in subform1, the coresponding record in subform 2
appears. You can then enter data in subform2. As data is entered in subform2,
it is totaled and must equal zero.

If the data in subform2 does not equal zero and you click on a different
record in subform1, the corresponding records appear in subform2 but I need
to have a test to check if the data in subform2 <> 0, then cancel the click
in subform1 and keep the records in subform2 displayed until the total in
subform2 = 0.

In other words:
Usually when you click on the record in the parent form, the child forms
records appear. If certain conditions are not met, I want to cancel the click
and cancel the change of records. Does anyone know how to do this?

Thanks
Mark
 
B

banem2

I have a form with 2 subforms.

MainForm
Subform1
Subform2

Subform1 is linked to MainForm
Subform2 is linked to Subform1

When you click on a record in subform1, the coresponding record in subform2
appears. You can then enter data in subform2. As data is entered in subform2,
it is totaled and must equal zero.

If the data in subform2 does not equal zero and you click on a different
record in subform1, the corresponding records appear in subform2 but I need
to have a test to check if the data in subform2 <> 0, then cancel the click
in subform1 and keep the records in subform2 displayed until the total in
subform2 = 0.

In other words:
Usually when you click on the record in the parent form, the child forms
records appear. If certain conditions are not met, I want to cancel the click
and cancel the change of records. Does anyone know how to do this?

Thanks
Mark

You need some code in BeforeUpdate of subform2:

Private Sub Form2_BeforeUpdate(Cancel As Integer)
If NZ(myField1) + NZ(myField2) <> 0 Then
MsgBox "Data entered did not pass validation test."
Cancel = True
'Me.Undo 'uncomment to undo changes
End If
End Sub

Regards,
Branislav Mihaljev, Microsoft Access MVP
 

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