Test for data in subform not working properly

C

CJ

Hi groupies.

If a subform contains data I want a message box to pop up and tell the user
that they can not delete the customer (instead of the default access
message) when they click on the delete customer button. I can't seem to get
the test for the data in the subform to work properly.

My code is as follows:

Private Sub cmdCustomerDelete_Click()
On Error GoTo Err_cmdCustomerDelete_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

If IsNull(Me![fsubOrders].Form![dtmOrderDate] = False) Then
MsgBox "Can Not Delete Customer With Orders In The System",
vbCritical"
End If

Exit_cmdCustomerDelete_Click:
Exit Sub

Err_cmdCustomerDelete_Click:
MsgBox "Deletion Cancelled", vbInformation"
Resume Exit_cmdCustomerDelete_Click

End Sub

My "Deletion Cancelled" message box works, but not "Can Not Delete
Customer..."

Can somebody please help me out.

Thanks
 
M

Marshall Barton

CJ said:
Hi groupies.

If a subform contains data I want a message box to pop up and tell the user
that they can not delete the customer (instead of the default access
message) when they click on the delete customer button. I can't seem to get
the test for the data in the subform to work properly.

My code is as follows:

Private Sub cmdCustomerDelete_Click()
On Error GoTo Err_cmdCustomerDelete_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

If IsNull(Me![fsubOrders].Form![dtmOrderDate] = False) Then
MsgBox "Can Not Delete Customer With Orders In The System",
vbCritical"
End If

Exit_cmdCustomerDelete_Click:
Exit Sub

Err_cmdCustomerDelete_Click:
MsgBox "Deletion Cancelled", vbInformation"
Resume Exit_cmdCustomerDelete_Click

End Sub

My "Deletion Cancelled" message box works, but not "Can Not Delete
Customer..."


The If statement will never have a True comdition, because
you have the =False inside the parenthesis.

OTOH, why give the users a chance to make this mistake? It
seems like it shouldn't be too dificult to disable the
button when there are dependent records. I don't know all
the details of what you've got going on here, but you might
not need much more than setting the button's Enabled
property in a couple of places.

In the main form's Current event:

button.Enabled = (subform.Form.Recordset.RecordCount = 0)

and in the subform's AfterInsert and AfterDelConfirm event:

Parent.button.Enabled = (Me.Recordset.RecordCount = 0)
 
C

CJ

Thanks Marshall.

I understand my error and I like your alternative.

Thanks again.
CJ

Marshall Barton said:
CJ said:
Hi groupies.

If a subform contains data I want a message box to pop up and tell the
user
that they can not delete the customer (instead of the default access
message) when they click on the delete customer button. I can't seem to
get
the test for the data in the subform to work properly.

My code is as follows:

Private Sub cmdCustomerDelete_Click()
On Error GoTo Err_cmdCustomerDelete_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

If IsNull(Me![fsubOrders].Form![dtmOrderDate] = False) Then
MsgBox "Can Not Delete Customer With Orders In The System",
vbCritical"
End If

Exit_cmdCustomerDelete_Click:
Exit Sub

Err_cmdCustomerDelete_Click:
MsgBox "Deletion Cancelled", vbInformation"
Resume Exit_cmdCustomerDelete_Click

End Sub

My "Deletion Cancelled" message box works, but not "Can Not Delete
Customer..."


The If statement will never have a True comdition, because
you have the =False inside the parenthesis.

OTOH, why give the users a chance to make this mistake? It
seems like it shouldn't be too dificult to disable the
button when there are dependent records. I don't know all
the details of what you've got going on here, but you might
not need much more than setting the button's Enabled
property in a couple of places.

In the main form's Current event:

button.Enabled = (subform.Form.Recordset.RecordCount = 0)

and in the subform's AfterInsert and AfterDelConfirm event:

Parent.button.Enabled = (Me.Recordset.RecordCount = 0)
 

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

Similar Threads


Top