MSAC2K -- Locking forms to prevent edits....

D

David Dubroff

Microsoft Access 2000 Question:

What is the best way to toggle a form for locking and unlocking the ability
to edit existing data?

Should I toggle the "AllowEdits" parameter based upon its current value? If
so, how do I accomplish this?

I am not sure how to get VBA to grab the current value of the "AllowEdits"
parameter.

Or.... should I be considering a "For....Next" loop to alter the "Enabled"
property for all controls. If so, how do I accomplish this?

What I would like to have is some object on the form that displays the
current "Lock / Unlock" status. Nearby to this status indicator should be
some way to change the form between the locked and unlocked status.

Please advise....

Dave
 
N

Nikos Yannacopoulos

David,

To toggle allow edits yes/no, lace the following line of
code in the click event of the button:

Forms("FormName").AllowEdits = Not Forms
("FormName").AllowEdits
Forms("FormName").Controls("Label1").Caption = "Editing
allowed: " & Forms("FormName").AllowEdits

The second line will display current status in a label
(Label1) on your form (add the label).
Modify names accordingly and make sure the default label
caption corresponds to the default status on form open.

HTH,
Nikos
 
D

David Dubroff

I tried the following lie of code within the OnClick of a button:

Forms("Top_Level").AllowEdits = Not Forms("Top_Level").AllowEdits

When I click the button, the form gets unlocked for edits. However, when I
click the button again, the form is not locked for edits.

The form initially opens as locked. I want to be able to have one button on
the form that switches the form between locked and unlocked for edits.

Please advise...
Dave
 
D

David Dubroff

I managed to get the following code to work for toggling the form between
being locked and unlocked for edits.

If Me.AllowEdits = False Then
Me.AllowEdits = True
DoCmd.RunCommand acCmdRefresh
Exit Sub
End If
If Me.AllowEdits = True Then
Me.AllowEdits = False
DoCmd.RunCommand acCmdRefresh
Exit Sub
End If
 
N

NIkos Yannacopoulos

David,

I'm really surprised it didn't work... it works fine for
me (A2K, W2K). Anyway, glad you solved your problem.

Best,
Nikos
 

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