Set Form Control Enabled Property to 'Yes' with VB

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,462
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. 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 :
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
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 :)
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try one of the other events.

Perhaps On Current.
 
Upvote 0
Thanks very much Norie - 'OnCurrent' was exactly what I needed.
Cheers, Andrew :)
 
Upvote 0

Forum statistics

Threads
1,221,899
Messages
6,162,682
Members
451,782
Latest member
LizN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top