Disabling a record!

  • Thread starter Thread starter Nightman
  • Start date Start date
N

Nightman

Hi
I have a check box called "completed", which I would like to programmed to
enable or disable the current record form by clicking it.

Anyone have a simple code?
 
to suggest simple (or complex) code, we need to understand exactly what
you're trying to accomplish.

by "disable", do you mean you don't want the user to be able to edit the
record? and is that checkbox bound to a field in the table? so if the box is
checkmarked in record 10, for example, then every time you move to record 10
in that form, you want the record to be un-editable? once the "completed"
checkbox is checked, do you want it protected as well? or do you want the
user to be able to un-check the box if, for instance, s/he checkmarked it by
accident, or thought the record was complete only to find that data is
incorrect or missing so that the record is actually not complete after all?

hth
 
Tina,
Thank you for your post.
This is what I want.
I have a form called "ORDERS" and the form has many fields and a subform.
then there is a checkbox called "Completed". this check box is bound to the
a field in database.
If the check box is checked, the user should not be able to edit any of the
fields in the current record. unchecking the checkbox should enable the
fields to editable again.
I also need to show the fields in the form looks "disabled in gray"
Every time the user move to disabled record in the form, I want the record
to be un-editable.

regards
Nathan

tina said:
to suggest simple (or complex) code, we need to understand exactly what
you're trying to accomplish.

by "disable", do you mean you don't want the user to be able to edit the
record? and is that checkbox bound to a field in the table? so if the box
is
checkmarked in record 10, for example, then every time you move to record
10
in that form, you want the record to be un-editable? once the "completed"
checkbox is checked, do you want it protected as well? or do you want the
user to be able to un-check the box if, for instance, s/he checkmarked it
by
accident, or thought the record was complete only to find that data is
incorrect or missing so that the record is actually not complete after
all?

hth
 
try the following code, as

Private Sub isProtectRecord()

On Error Resume Next

Dim ctrl As Object

For Each ctrl In Me.Controls
ctrl.Enabled = Not Me!Completed
Next ctrl

If Me!Completed.Enabled = False Then Me!Completed.Enabled = True

End Sub

note that the code "toggles" the Enabled property all controls on the form,
according to the value of the Completed checkbox - then it goes back and
enables the Completed checkbox specifically, if it was disabled. if you have
other specific control(s) on your form (such as certain command buttons, for
example) that should NOT be disabled at any time, then add an If statement
for each one, to make sure it is always enabled.

call the code from the form's Current event procedure, and also from the
Completed checkbox's Click event procedure, as

Private Sub Completed_Click()

isProtectRecord

End Sub

Private Sub Form_Current()

isProtectRecord

End Sub

hth


Nightman said:
Tina,
Thank you for your post.
This is what I want.
I have a form called "ORDERS" and the form has many fields and a subform.
then there is a checkbox called "Completed". this check box is bound to the
a field in database.
If the check box is checked, the user should not be able to edit any of the
fields in the current record. unchecking the checkbox should enable the
fields to editable again.
I also need to show the fields in the form looks "disabled in gray"
Every time the user move to disabled record in the form, I want the record
to be un-editable.

regards
Nathan
 
Thank you. it worked. Great..

tina said:
try the following code, as

Private Sub isProtectRecord()

On Error Resume Next

Dim ctrl As Object

For Each ctrl In Me.Controls
ctrl.Enabled = Not Me!Completed
Next ctrl

If Me!Completed.Enabled = False Then Me!Completed.Enabled = True

End Sub

note that the code "toggles" the Enabled property all controls on the
form,
according to the value of the Completed checkbox - then it goes back and
enables the Completed checkbox specifically, if it was disabled. if you
have
other specific control(s) on your form (such as certain command buttons,
for
example) that should NOT be disabled at any time, then add an If statement
for each one, to make sure it is always enabled.

call the code from the form's Current event procedure, and also from the
Completed checkbox's Click event procedure, as

Private Sub Completed_Click()

isProtectRecord

End Sub

Private Sub Form_Current()

isProtectRecord

End Sub

hth
 
Back
Top