Allow editing

R

Rolf Rosenquist

I have a form that is locked for editing already by opening the form. In the
code I use the line "Me.AllowEdits = Me.NewRecord" so that only new records
can be written.

Now I need to let the user be able to change one single field also on old
records. How can I let him do that? I have tried "Field.Locked = False" and
"Field.Enabled = True" but it does not help.

/ Rolf
 
A

Allen Browne

If you set the form's AllowEdits property to Yes, you will not be able to
use any controls for editing, regardless of their Locked property.

You need to leave AllowEdits as No, and set the Locked property to No for
all the control other than the one the one you allow. Of course they have be
be set back to Yes for new records.

Use the code in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The article explains how to call the code from a command button, but in your
case you will want to call it from the Current event of the form, like this:
Call LockBoundControls(Me, Not Me.NewRecord, "NameOfControlToNotLock")
 
R

Rolf Rosenquist

Followed your example, but got an error for the code
"=LockBoundControls([Form],True)"
when I wrote it in the code at Private Sub Form_Load(). It says after
translation to English something like: "Compiling error: Expected: a row
number or a row label or a program statement or end of program statement."

Maybe I have tried to put it in the wrong place, but I could not find an On
Load property for the form. Should it be somewhere else?
/ Rolf
 
A

Allen Browne

You can put it inside the event procedure code if you wish.
Use:
Call LockBoundControls(Me, True)

But I would have thought this would need to go into the form's Current event
rather than its Load event for your case, and the 2nd argument would be:
Not Me.NewRecord
rather than True, and you would need to pass the name of the control that
should be left unlocked as well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Rolf Rosenquist said:
Followed your example, but got an error for the code
"=LockBoundControls([Form],True)"
when I wrote it in the code at Private Sub Form_Load(). It says after
translation to English something like: "Compiling error: Expected: a row
number or a row label or a program statement or end of program statement."

Maybe I have tried to put it in the wrong place, but I could not find an
On
Load property for the form. Should it be somewhere else?
/ Rolf





Allen Browne said:
If you set the form's AllowEdits property to Yes, you will not be able to
use any controls for editing, regardless of their Locked property.

You need to leave AllowEdits as No, and set the Locked property to No for
all the control other than the one the one you allow. Of course they have be
be set back to Yes for new records.

Use the code in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The article explains how to call the code from a command button, but in your
case you will want to call it from the Current event of the form, like this:
Call LockBoundControls(Me, Not Me.NewRecord,
"NameOfControlToNotLock")
 
R

Rolf Rosenquist

Now most of it works as I wanted, but there is one little thing left. All
the controls work exactly as you say when I click the Unlock button. But
some of the fields, named A, B and C should not be able to edit. I tried to
put them as arguments, also as Not A..., but it did not work. Can that be
done?

/ Rolf


Allen Browne said:
You can put it inside the event procedure code if you wish.
Use:
Call LockBoundControls(Me, True)

But I would have thought this would need to go into the form's Current event
rather than its Load event for your case, and the 2nd argument would be:
Not Me.NewRecord
rather than True, and you would need to pass the name of the control that
should be left unlocked as well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Rolf Rosenquist said:
Followed your example, but got an error for the code
"=LockBoundControls([Form],True)"
when I wrote it in the code at Private Sub Form_Load(). It says after
translation to English something like: "Compiling error: Expected: a row
number or a row label or a program statement or end of program statement."

Maybe I have tried to put it in the wrong place, but I could not find an
On
Load property for the form. Should it be somewhere else?
/ Rolf





Allen Browne said:
If you set the form's AllowEdits property to Yes, you will not be able to
use any controls for editing, regardless of their Locked property.

You need to leave AllowEdits as No, and set the Locked property to No for
all the control other than the one the one you allow. Of course they
have
be
be set back to Yes for new records.

Use the code in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The article explains how to call the code from a command button, but in your
case you will want to call it from the Current event of the form, like this:
Call LockBoundControls(Me, Not Me.NewRecord,
"NameOfControlToNotLock")

I have a form that is locked for editing already by opening the form. In
the
code I use the line "Me.AllowEdits = Me.NewRecord" so that only new
records
can be written.

Now I need to let the user be able to change one single field also on old
records. How can I let him do that? I have tried "Field.Locked = False"
and
"Field.Enabled = True" but it does not help.
 
A

Allen Browne

Include the control names, in quotes and separated by commas, inside the
brackets, e.g.:

Call LockBoundControls(Me, Not Me.NewRecord, "A", "B", "C")

You can list as many as you need.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Rolf Rosenquist said:
Now most of it works as I wanted, but there is one little thing left. All
the controls work exactly as you say when I click the Unlock button. But
some of the fields, named A, B and C should not be able to edit. I tried
to
put them as arguments, also as Not A..., but it did not work. Can that be
done?

/ Rolf


Allen Browne said:
You can put it inside the event procedure code if you wish.
Use:
Call LockBoundControls(Me, True)

But I would have thought this would need to go into the form's Current event
rather than its Load event for your case, and the 2nd argument would be:
Not Me.NewRecord
rather than True, and you would need to pass the name of the control that
should be left unlocked as well.

Rolf Rosenquist said:
Followed your example, but got an error for the code
"=LockBoundControls([Form],True)"
when I wrote it in the code at Private Sub Form_Load(). It says after
translation to English something like: "Compiling error: Expected: a
row
number or a row label or a program statement or end of program statement."

Maybe I have tried to put it in the wrong place, but I could not find
an
On
Load property for the form. Should it be somewhere else?
/ Rolf

"Allen Browne" <[email protected]> skrev i meddelandet
If you set the form's AllowEdits property to Yes, you will not be able to
use any controls for editing, regardless of their Locked property.

You need to leave AllowEdits as No, and set the Locked property to No for
all the control other than the one the one you allow. Of course they have
be
be set back to Yes for new records.

Use the code in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The article explains how to call the code from a command button, but
in
your
case you will want to call it from the Current event of the form, like
this:
Call LockBoundControls(Me, Not Me.NewRecord,
"NameOfControlToNotLock")

I have a form that is locked for editing already by opening the form. In
the
code I use the line "Me.AllowEdits = Me.NewRecord" so that only new
records
can be written.

Now I need to let the user be able to change one single field also
on
old
records. How can I let him do that? I have tried "Field.Locked = False"
and
"Field.Enabled = True" but it does not help.
 
R

Rolf Rosenquist

Yes I thought so, and that was exactly what I did, but it doesn't work. This
line is copied from the code.
Call LockBoundControls(Me, Not Me.NewRecord, "utA"), but I cannot have
the"utA" to stay locked.
/ Rolf




Allen Browne said:
Include the control names, in quotes and separated by commas, inside the
brackets, e.g.:

Call LockBoundControls(Me, Not Me.NewRecord, "A", "B", "C")

You can list as many as you need.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Rolf Rosenquist said:
Now most of it works as I wanted, but there is one little thing left. All
the controls work exactly as you say when I click the Unlock button. But
some of the fields, named A, B and C should not be able to edit. I tried
to
put them as arguments, also as Not A..., but it did not work. Can that be
done?

/ Rolf


Allen Browne said:
You can put it inside the event procedure code if you wish.
Use:
Call LockBoundControls(Me, True)

But I would have thought this would need to go into the form's Current event
rather than its Load event for your case, and the 2nd argument would be:
Not Me.NewRecord
rather than True, and you would need to pass the name of the control that
should be left unlocked as well.

Followed your example, but got an error for the code
"=LockBoundControls([Form],True)"
when I wrote it in the code at Private Sub Form_Load(). It says after
translation to English something like: "Compiling error: Expected: a
row
number or a row label or a program statement or end of program statement."

Maybe I have tried to put it in the wrong place, but I could not find
an
On
Load property for the form. Should it be somewhere else?
/ Rolf

"Allen Browne" <[email protected]> skrev i meddelandet
If you set the form's AllowEdits property to Yes, you will not be
able
to
use any controls for editing, regardless of their Locked property.

You need to leave AllowEdits as No, and set the Locked property to
No
for
all the control other than the one the one you allow. Of course they have
be
be set back to Yes for new records.

Use the code in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The article explains how to call the code from a command button, but
in
your
case you will want to call it from the Current event of the form, like
this:
Call LockBoundControls(Me, Not Me.NewRecord,
"NameOfControlToNotLock")

I have a form that is locked for editing already by opening the
form.
In
the
code I use the line "Me.AllowEdits = Me.NewRecord" so that only new
records
can be written.

Now I need to let the user be able to change one single field also
on
old
records. How can I let him do that? I have tried "Field.Locked = False"
and
"Field.Enabled = True" but it does not help.
 
R

Rolf Rosenquist

With help of your earlier inputs, I came up with another idea to do it. Not
elegant, but I did lock all the normal fields A, B, C...except the one that
should be editable when inside an old record and made the opposite when in a
new record.

Thanks for helping me with ideas. Regards

/ Rolf


Allen Browne said:
Include the control names, in quotes and separated by commas, inside the
brackets, e.g.:

Call LockBoundControls(Me, Not Me.NewRecord, "A", "B", "C")

You can list as many as you need.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Rolf Rosenquist said:
Now most of it works as I wanted, but there is one little thing left. All
the controls work exactly as you say when I click the Unlock button. But
some of the fields, named A, B and C should not be able to edit. I tried
to
put them as arguments, also as Not A..., but it did not work. Can that be
done?

/ Rolf


Allen Browne said:
You can put it inside the event procedure code if you wish.
Use:
Call LockBoundControls(Me, True)

But I would have thought this would need to go into the form's Current event
rather than its Load event for your case, and the 2nd argument would be:
Not Me.NewRecord
rather than True, and you would need to pass the name of the control that
should be left unlocked as well.

Followed your example, but got an error for the code
"=LockBoundControls([Form],True)"
when I wrote it in the code at Private Sub Form_Load(). It says after
translation to English something like: "Compiling error: Expected: a
row
number or a row label or a program statement or end of program statement."

Maybe I have tried to put it in the wrong place, but I could not find
an
On
Load property for the form. Should it be somewhere else?
/ Rolf

"Allen Browne" <[email protected]> skrev i meddelandet
If you set the form's AllowEdits property to Yes, you will not be
able
to
use any controls for editing, regardless of their Locked property.

You need to leave AllowEdits as No, and set the Locked property to
No
for
all the control other than the one the one you allow. Of course they have
be
be set back to Yes for new records.

Use the code in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The article explains how to call the code from a command button, but
in
your
case you will want to call it from the Current event of the form, like
this:
Call LockBoundControls(Me, Not Me.NewRecord,
"NameOfControlToNotLock")

I have a form that is locked for editing already by opening the
form.
In
the
code I use the line "Me.AllowEdits = Me.NewRecord" so that only new
records
can be written.

Now I need to let the user be able to change one single field also
on
old
records. How can I let him do that? I have tried "Field.Locked = False"
and
"Field.Enabled = True" but it does not help.
 
A

Allen Browne

Yes, that's the idea. You set the Locked state for these controls the way
you want them, and the code ignores them when you add their name to the
exception list.

All the best
 
Top