New detail records being added despite disabled button in master form

BlueSpruce

Well-known member
Local time
Yesterday, 23:22
Joined
Jul 18, 2025
Messages
1,214
I have a customer form that won't enable a button for opening a popup modal form for adding related contracts unless a customer is selected, and the customer's status is normal.

In the customer form's On Current event, I have the following code that locks the Add Contract button if the customer status is not Normal, yet users have been adding new contracts despite the status not being normal. The Add Contract modal form cannot be opened by itself, so I am baffled as to how users have been adding contracts for deceased customers.

Code:
Private Sub Form_Current()
  
   On Error GoTo locErrorHandler

   cmdSave.Transparent = True
   cmdUndo.Transparent = True
 
'4/17/2024 Efrain: Checks to see if customer has normal status.  If not then makes ribbon red and disables new contract button

   Dim lngRed As Long, lngGreen As Long
  
   lngRed = RGB(255, 0, 0)
   lngGreen = RGB(35, 183, 77)
    
   If Me.cboCustomerStatusID = 1 Then  'Normal Status
        Me.txtDisplayCustomer.BackColor = lngGreen
        Me.txtDisplayStatus.BackColor = lngGreen
        Me.cmdNewContract.Enabled = True
        
        DoCmd.GoToControl cmdNewContract.Name

   Else        'everything else
        Me.txtDisplayCustomer.BackColor = lngRed
        Me.txtDisplayStatus.BackColor = lngRed
        Me.cmdNewContract.Enabled = False
        
        DoCmd.GoToControl cmdClose.Name

   End If
    
locExitHere:
   Exit Sub
  
locErrorHandler:
   ErrorHandler Me.Name, "frmCustomer, On Current Event"
   If gErrorResponse = 1 Then Resume
   If gErrorResponse = 2 Then Resume Next
   Resume locExitHere
  
End Sub

frmCustomer.PNG
 
if customer is NOT selected then the ID will be NULL. Add NZ to the if.

If NZ(Me.cboCustomerStatusID, 0) = 1 Then 'Normal Status
 
I'm not sure Ron's suggestion is the answer. If the customer is null you should fall through to the Else anyway.

I'm on my phone and can't see your image very clearly. Are you sure the subform has AllowAdditions property set to False? Could they be adding a new record via the navigation buttons?
 
if customer is NOT selected then the ID will be NULL. Add NZ to the if.

If NZ(Me.cboCustomerStatusID, 0) = 1 Then 'Normal Status

AllowAdditions property in the subform is set to False. The subform is readonly. Clicking anywhere on a subform row opens the contract form with the selected Contract#. The "Add Contract" button is not enabled unless there's a customer in the On Current event. It's not going to let you add an orphaned Contract without a related customer. The only thing I can think of is bypassing the form and adding a Contract record directly in the table. I have seen users who do that, and other tricks like changing the system date to enter pre and post dated records.

tblContract.PNG
 
Last edited:
If the button is in the sub-form, you need to add the sub-form to the reference.

Me.SubFormControlName.Form.cmdNewContact.Enabled = False
 
Are users able to change the status?

Yes. If users changed status to 'Normal', added new contracts, then changed status back to 'Deceased', then that would explain the issue.
However, I have a history table that tracks changes to the Customer Profile and I would have noticed that workaround, and they didn't do that.

CustomerHistoryAudit.PNG
 
If the button is in the sub-form, you need to add the sub-form to the reference.

Me.SubFormControlName.Form.cmdNewContact.Enabled = False

The "Add New Contract" button is not in the subform, it's in the parent Customer form.

DesignView.PNG
 
Last edited:
Do you have contracts without a related customer record? Is there a default value in the Customer field of the contracts table?
 
Do you have contracts without a related customer record? Is there a default value in the Customer field of the contracts table?

Nope, there's no orphaned contract records in the table, they all have a CustomerID in the foreign key.

The default value for "Status" when adding a new customer is "Normal"

AddNewCustomer.PNG
 
The only thing I can think of is bypassing the form and adding a Contract record directly in the table. I have seen users who do that, and other tricks like changing the system date to enter pre and post dated records.
How is that possible?
Do the users have direct access to the tables?
 
Then you have a much bigger problem the a button being enabled when it should be disabled. You have no data integrity!
The button is properly disabled when it should be.
I repeat, I did not find any orphaned records.

B22B2CDD-58DC-417C-867C-6237918F363F.png

https___www.access-programmers.co.uk_forums_attachments_designview-png.122482_.png
 
Last edited:

Users who are viewing this thread

Back
Top Bottom