With currentForm
.varName = False
!ctrlName.Enabled = True
End With
...
The line with the bang does not run. The error msg is
something along the lines that the control cannot be found.
The bang operator refers to a member of the default collection, and in the
case of a Form object this is the Controls collection, so the code you have
offered should be right. There are some possible confounders, however.
The first thing to check is that ctrlName actually exists on the form --
and this should be a control actually called "ctrlName". If ctrlName is a
string containing the name ("txtMyTextBox") then you need the fuller syntax
With frmCurrentForm
.Controls(strCtrlName).Enabled = True
End With
The next is when there is a collision between the properties of a form, the
fields in the recordset the form is based on, and the controls. Access
exposes all the fields in the recordset as form properties, so that
frmCurrentForm.AnnualCost
returns the value from the database. Contrast this with
frmCurrentForm!AnnualCost
which reads the value in the control. Although these are the same
practically all the time, there are situations where you need to be able to
refer definitely to one or the other. Finally, if you have a field called
Caption, then the following can cause great confusion:
frmCurrentForm.Caption
All this is a good reason for using some form of data-type labelling of
your variables. It does force you continually to bear in mind whether you
are referring to an object, or a string containing a name, or a property or
a handle or whatever. The prefix method I used here is common, but you can
use something else as long as it makes sense to you and your successors.
Hope that helps
Tim F