Enabling/disabling fields on a form

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

Guest

How would I disable all fields on a form for a specific record? Right now I
have a checkbox set up that controls which fields are enabled/disabled but is
there an easier way to disable all fields instead of typing them all into my
"If" statement? The reason I am doing this is because if a specific record
needs to be voided I don't want to delete it, just disable that particular
record.
 
you could write code to loop through the controls and disable/enable them,
or you could set the form's AllowEdits property to False/True.

hth
 
Hi Secret Squirrel,

A strategy that I use is to add a Yes/No (boolean) field to a table, which
is used in the criteria for a form's recordsource. For example, you might
name such a field something like blnInactiveRecord with a default value of 0
(false). Then in the criteria of the query used as the form's recordsource,
add this field:

....WHERE blnInactiveRecord <> 0

The record isn't even displayed to the user, so there's no need to lock
anything.

Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

How would I disable all fields on a form for a specific record? Right now I
have a checkbox set up that controls which fields are enabled/disabled but is
there an easier way to disable all fields instead of typing them all into my
"If" statement? The reason I am doing this is because if a specific record
needs to be voided I don't want to delete it, just disable that particular
record.
 
Oops....meant to write:

....WHERE blnInactiveRecord = 0


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

Hi Secret Squirrel,

A strategy that I use is to add a Yes/No (boolean) field to a table, which
is used in the criteria for a form's recordsource. For example, you might
name such a field something like blnInactiveRecord with a default value of 0
(false). Then in the criteria of the query used as the form's recordsource,
add this field:

....WHERE blnInactiveRecord <> 0

The record isn't even displayed to the user, so there's no need to lock
anything.

Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

How would I disable all fields on a form for a specific record? Right now I
have a checkbox set up that controls which fields are enabled/disabled but is
there an easier way to disable all fields instead of typing them all into my
"If" statement? The reason I am doing this is because if a specific record
needs to be voided I don't want to delete it, just disable that particular
record.
 
Can you possibly help me create this loop code? I don't know too much about
how to do that. Would I add this to my "IF" statement?
 
try

Dim ctrl As Object

On Error Resume Next

For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox _
Or TypeOf ctrl Is ComboBox _
Or TypeOf ctrl Is CheckBox Then
ctrl.Enabled = Me!CheckboxName
End If
Next

the above code assumes that there are textboxes, comboboxes and checkboxes
on the form that you want to enable/disable. alter the code to suit your
needs; for instance, if there are no comboboxes on the form, or none that
you want affected, then remove that reference in the If statement.

you said you "have a checkbox set up that controls which fields are
enabled/disabled". the line of code

ctrl.Enabled = Me!CheckboxName

is essentially a toggle; when that checkbox is checkmarked (equals True)
then Enabled = True; when there is no checkmark, then Enabled = False.
substitute the correct name of the checkbox for "CheckboxName" in the code,
of course.

hth
 
Tina,
That's close to what I want. It does work but in reverse. When I put a check
in the "Void" checkbox I want all the fields to be disabled but only for that
specific record. And I don't want the labels to be disabled, just the fields
themselves. How would I fix this?
 
comments inline.

Secret Squirrel said:
Tina,
That's close to what I want. It does work but in reverse.

okay. change the "toggle" line of code to

ctrl.Enabled = Not Me!CheckboxName

so if the checkbox is checkmarked (True) then Enabled = False, and vice
versa.
When I put a check
in the "Void" checkbox I want all the fields to be disabled but only for that
specific record.

you have to run the code in two places: the Void checkbox's AfterUpdate or
Click event, AND the form's Current event. also, you have to consider
whether you want the user to be able to "un-void" a record. if so, you don't
want VBA code to disable that particular checkbox control. to deal with that
issue, try this modified code, as

Dim ctrl As Object

On Error Resume Next

For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox _
Or TypeOf ctrl Is ComboBox _
Or (TypeOf ctrl Is CheckBox And _
(Not ctrl.Name = "CheckboxName")) Then
ctrl.Enabled = Me!CheckboxName
End If
Next

if you're using a Continuous form, you may still not get the effect you're
hoping for - but i won't go into that unless it is an issue for you.
And I don't want the labels to be disabled, just the fields
themselves. How would I fix this?

AFAIK, that can't be done as long as the label is associated with the
control. (a quick test of "associated": if you click on only the control in
design view, and drag it somewhere, the label moves along with it. bingo,
the label is associated with the control.) when a control is
disabled/enabled, or hidden/shown (Visible property), the label exhibits the
same behavior.

to get around that behavior, you can dis-associate a label from a control.
in design view, click on the control's label only and press Ctrl+c to copy
the label. then click anywhere in the form (not on another control) to
de-select the label, and press Ctrl+v to paste. now you have an identical
label, but it is not associated with any control, so it won't be affected by
anything you do to a control. just delete the original label.

hth
 
Hi Tina,
That worked perfectly this time around. I had the code in both events but
for some reason it was disabling all the records. But it's working fine now.
I already have it set up to only allow certain users to even use that
checkbox so I won't have to worry about people using it that aren't supposed
to be. As for the labels, well that could take some time since there are 65
fields on my form so I'll just let everything get disabled. It would take way
too long to change all the labels so I'll just leave it.

Thanks for all your help! I appreciate it!
 
Actually I do have one more question. I have 3 fields on my form that are
used soley for calculations and they are not disabling when I check the box.
They are all textboxes so why aren't they disabling with the rest? Is it
because they are not bound?
 
you're welcome :)


Secret Squirrel said:
Hi Tina,
That worked perfectly this time around. I had the code in both events but
for some reason it was disabling all the records. But it's working fine now.
I already have it set up to only allow certain users to even use that
checkbox so I won't have to worry about people using it that aren't supposed
to be. As for the labels, well that could take some time since there are 65
fields on my form so I'll just let everything get disabled. It would take way
too long to change all the labels so I'll just leave it.

Thanks for all your help! I appreciate it!
 
well, AFAIK, when the code includes textbox types in the If statement, all
textbox controls on the form should be affected the same. i'd have to test
it to be sure, but since calculated controls can't be edited by the user
anyway, it's kind of a moot point in this instance, so...

hth
 
-\0-\0-\0-\0-\0O\0r\0i\0g\0i\0n\0a\0l\0 \0M\0e\0s\0s\0a\0g\0e\0-\0-\0-\0-\0-
F\0r\0o\0m\0:\0 \0t\0i\0n\0a\0 \0[\0m\0a\0i\0l\0t\0o\0:\0n\0o\0s\0p\0a\0m\0@\0a\0d\0d\0r\0e\0s\0s\0.\0c\0o\0m\0]
P\0o\0s\0t\0e\0d\0 \0A\0t\0:\0 \0S\0u\0n\0d\0a\0y\0,\0 \0D\0e\0c\0e\0m\0b\0e\0r\0 \01\01\0,\0 \02\00\00\05\0 \01\00\0:\02\05\0 \0P\0M
P\0o\0s\0t\0e\0d\0 \0T\0o\0:\0 \0m\0i\0c\0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