Andrew Fergus
MrExcel MVP
- Joined
- Sep 9, 2004
- Messages
- 5,462
- Office Version
- 365
- 2021
- 2016
- Platform
- Windows
I have a form based on a query, one of the fields is titled "Entity_Next_Invoice_Number" (the name and the control source) which shows the next invoice number for each entity. I have written a script that automatically sets the enabled property of this field to 'Yes' if the value is either null or zero and sets it to 'No' otherwise. Unfortunately it doesn't work properly. This is the code I have put into the 'On Load' event for the form :
This doesn't work properly - whatever the value is of the "Entity_Next_Invoice_Number" field for the the first record sets the enabled property for every record on the form (i.e. if the first record has a value >0 then every record has enabled set to 'No' and if the first record has a value = 0, then every record has enabled set to 'Yes'). What have I done wrong? Is it the Me! part of should this script not be in the 'On Load' event of the form?
TIA, Andrew
Code:
Private Sub Form_Load()
On Error GoTo Err_Form_Load
DoCmd.Restore
If Nz(Me!Entity_Next_Invoice_Number) = 0 Then
Me!Entity_Next_Invoice_Number.Enabled = True
Else
Me!Entity_Next_Invoice_Number.Enabled = False
End If
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
End Sub
TIA, Andrew