Do Until/Command Button

M

mb

Is there a way to write a code that will disable all the fields on the
current record of a form until an "Edit This Record" command button is
clicked?
 
D

Douglas J. Steele

Imron2 via AccessMonster.com said:
I use ther form properties

With Form_XXX
.AllowEdits = False

when I want to allow edits (ie. "Edit This Record" command button )
change to
.AllowEdits = True

For the sake of completeness, note that that code would be put in the form's
Current event so that it's executed as you move from record to record.
 
M

mb

Thanks for your help, but I'm a little confused. I'm not very advanced in
Access, but here's what was in my code originally. I don't know how to write
the code to say when the "Edit This Record" button is clicked, then change
..Enabled to True. Am I off to a bad start? Should .Enabled be changed to
..AllowEdits?


Private Sub Form_Current()

[CATEGORY #].Enabled = False
[CATEGORY NAME].Enabled = False

End Sub
 
M

Marshall Barton

mb said:
Is there a way to write a code that will disable all the fields on the
current record of a form until an "Edit This Record" command button is
clicked?


You probably want to use Lock instead of Disable. The
answer is the same in either case.

You can not disable "fields", you can only disable controls.
However you can not disable every kind of control (e.g.
label). You also do not want to disable every control that
can be disabled (e.g. the "Edit This Record" command
button).

So, the question is more about how to identify the controls
that should be disabled. A common technique is to set these
controls' Tag property to something like Block. Then the
code could look like:

Private Function DoEnable(OnOff As Boolean)
Dim ctl As Control
For Each ctl Me.Controls
If ctl.Tag = "Block" Then ctl.Enabled = OnOff
Next ctl
End Function

And the form's Current event can disable the controls with:
DoEnable False
and your button can enable the controls using:
DoEnable True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top