AllowEdits

B

Bob Quintal

=?Utf-8?B?U2VjcmV0IFNxdWlycmVs?=
I'm using the "AllowEdits" to lock records so they can't be edited
unless it's a new record. I also have a combo box on my forms
header that I use to search for records. When I have the
"AllowEdits" set so records can't be edited it also locks that
combo box as well and users can't search for records for viewing
purposes only. How can I continue to lock the records and also
allow users to select a record from the combo box on my forms
header?
Pick one of the following:
1) change the combo to a button that opens a little form with your
combobox, and have the code to move to the chosen record reference
the main form.

2) instead of locking controls globally with the allowEdits
property, loop through the form's controls collection, setting the
locked property of controls based on a) a prefix|suffix to the
control names, or b) use the tag property of each control to hold a
value which you test to see if that control should be locked.
 
G

Guest

I'm using the "AllowEdits" to lock records so they can't be edited unless
it's a new record. I also have a combo box on my forms header that I use to
search for records. When I have the "AllowEdits" set so records can't be
edited it also locks that combo box as well and users can't search for
records for viewing purposes only. How can I continue to lock the records and
also allow users to select a record from the combo box on my forms header?
 
D

Dirk Goldgar

In
Secret Squirrel said:
I'm using the "AllowEdits" to lock records so they can't be edited
unless it's a new record. I also have a combo box on my forms header
that I use to search for records. When I have the "AllowEdits" set so
records can't be edited it also locks that combo box as well and
users can't search for records for viewing purposes only. How can I
continue to lock the records and also allow users to select a record
from the combo box on my forms header?

It's a pain, isn't it? I wish AllowEdits only applied to bound
controls, or else there were a separate setting for that.

What you can do is leave AllowEdits set to Yes, but lock and unlock all
the bound controls, as needed. You can either name each specific
control in the code that locks or unlocks; e.g.,

Private Sub LockUnlock(bLocked As Boolean)

Me!Text1.Locked = bLocked
Me!Text2.Locked = bLocked
Me!Combo3.Locked = bLocked
' ... etc.

End Sub

Or else set the Tag property of all the controls you want to lock/unlock
to some specific value, and then loop through the controls to do it;
e.g.,

Private Sub LockUnlock(bLocked As Boolean)

Dim ctl As Access.Control

For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then ctl.Locked = bLocked
Next ctl

End Sub

Either way, to lock all the relevant controls, you would execute the
line

LockUnlock True

And to unlock them, you'd execute

LockUnlock False
 
G

Guest

I agree it is a pain. But here's the catch. I can't lock the records because
users still need to add new records through this form. I just want to lock
all records except for new ones. And also allow the combo box in the form's
header to still be accessible.
 
R

Rick Brandt

Secret said:
I agree it is a pain. But here's the catch. I can't lock the records
because users still need to add new records through this form. I just
want to lock all records except for new ones. And also allow the
combo box in the form's header to still be accessible.

He didn't say "lock the records". He said "...lock and unlock all the bound
controls as needed". That means you can unlock them on new records and lock
them on existing records.
 
D

Dirk Goldgar

In
Secret Squirrel said:
I agree it is a pain. But here's the catch. I can't lock the records
because users still need to add new records through this form. I just
want to lock all records except for new ones. And also allow the
combo box in the form's header to still be accessible.

So use the approach Bob Quintal and I suggested to lock all bound
controls except when it's a new record.

'----- start of example code -----
Private Sub Form_Current()

LockUnlock (Not Me.NewRecord)

End Sub
'----- end of example code -----
 

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