Changing Control Properties

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

dear all,

i have a continous form i want to make the enabled proeperty to a checkbox
disabled but in only one record not all the records


i tried to make this option but it is applied on all the records

can any one tell me how to do this option
 
Hi Walid,

To the best of my knowledge, that is not possible as the only way to do
it would be with conditional formatting -- but that is not available for
checkbox controls

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
Hi Walid,

Try this in the sample Northwind.mdb database:
Open the Product List form. The default view for this form is Continuous
Forms. Set the Allow Edits property to Yes. Paste the following code into a
new module associated with this form. I'm using a specific (hard coded)
ProductID value below, since you indicated that you only want to disable one
record. However, the same idea will work if you want to disable a category
of records.

Option Compare Database
Option Explicit

Private Sub Form_Current()
On Error GoTo ProcError

If Me.ProductID = 3 Then
Me.Discontinued.Locked = True
Me.Discontinued.Enabled = False
Else
Me.Discontinued.Locked = False
Me.Discontinued.Enabled = True
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_Current..."
Resume ExitProc
End Sub


This seems to work "sorta okay", when the form is opened either by itself,
or displayed as a subform of the Categories form. The only part that I don't
like is if you start from the record with ProductID = 3 ("Aniseed Syrup",
where the checkbox is locked with enabled set to false) and you click
*directly* into the checkbox for another record, then it takes two clicks in
order to actually change the state of the checkbox for the different record.
The reason is that focus cannot initially go to a control with the properties
set in this way, so focus goes instead to the Product Name textbox. At that
point, Form_Current runs which enables the checkbox, so you can now toggle
it's value.

Note: The does not work with a datasheet view.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
Update (courtesy of Access MVP A.D. Tejpal)

Apparently, the OP wishes to ensure that for certain category of
records, the check box on a continuous form should be non-editable. This
objective can be met by manipulating the locked property alone, without
disturbing the enabled property, which can remain permanently true.

In fact trying to manipulate the enabled property of check box would not
even be desirable, as any such command becomes ineffective on a direct click
(a control having focus can not be disabled).

Enter event of check box fires before its click and AfterUpdate events.
As such this event can be used directly, in lieu of form's current event.
Sample code in enter event of check box named ChkDiscontinued, as given at
(A) below, should get the desired results.

PClass is the name of field identifying the records where such locking
is to be enforced (in sample case, PClass = "D" is the criteria).
Simultaneously, such records can be specially highlighted via conditional
formatting, using the expression given at (B) below.

Best wishes,
A.D.Tejpal
--------------

(A) Code in form's module
================================
Private Sub ChkDiscontinued_Enter()
If Me.PClass = "D" Then
Me.ChkDiscontinued.Locked = True
Else
Me.ChkDiscontinued.Locked = False
End If
End Sub
================================

(B) Expression for conditional formatting
================================
[PClass]="D"
================================




Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
 
Back
Top