If Data in field, then prevent change

  • Thread starter Thread starter andy
  • Start date Start date
A

andy

Please pardon the cross posting (also in General
Questions, however I am not getting any answers)

Could someone please tell me (or show me where to put what
code) so that if a user navigates into a field where there
is already data (<> null)? or perhaps (<> "")? or both?
that they are prevented from changing the values in that
field only. I know how to prevent them from deleting a
whole record, but don't know how to do this on a field by
field basis.
Thank you in advance
God bless you
andy
 
andy said:
Please pardon the cross posting (also in General
Questions, however I am not getting any answers)

Could someone please tell me (or show me where to put what
code) so that if a user navigates into a field where there
is already data (<> null)? or perhaps (<> "")? or both?
that they are prevented from changing the values in that
field only. I know how to prevent them from deleting a
whole record, but don't know how to do this on a field by
field basis.

Here's how I would handle this.

Assuming there's more than a couple, I would give all controls where I wanted this
feature a common Tag property (like "Lock"). Then in the Form's Current event ...

Dim Cnt as Control

For Each Cnt in Me
If Cnt.Tag = "Lock" _
And Len(Nz(Cnt,""))>0 Then Cnt.Locked = True
Next Cnt
 
I assume you are using a form to enter the data. You could use the current
event of the form to disable and lock the controls in question if they
contain any data. A disabled/ locked control looks like a normal control,
but it's not possible to edit it.

If the data in question is in a field bound to a control called txtControl
then code something like this (untested) should work:

With Me.txtControl
If IsNull(.Value) Then
.Locked = True
.Enabled = False
Else
.Locked = False
.Enabled = True
End If
End With
 
Rick,

Thank you for your reply. I went into the properties of
one of the fields with which I want to do this, and named
the attribute of Tab to Lock. Is this what you ment? then
on the form I created a Form_Current event into which I
pasted your code. When I ran the formI got a Runtime error
437 Object doesn't support this property or method. Can
you tell what I did wrong. Thank you for your help. God
bless you for sharing your expertise.
 
Andrew,
Thank you for your help. On the form property I created an
event Form_current, and pasted your code into it changing
the control name to the field name txtID. When testing it
doesn't prevent me from changing existing data. Please let
me know if I did anything wrong. God bless you for sharing
your expertise.
 
andy said:
Rick,

Thank you for your reply. I went into the properties of
one of the fields with which I want to do this, and named
the attribute of Tab to Lock. Is this what you ment? then
on the form I created a Form_Current event into which I
pasted your code. When I ran the formI got a Runtime error
437 Object doesn't support this property or method. Can
you tell what I did wrong. Thank you for your help. God
bless you for sharing your expertise.

Sorry. That's the problem with Air Code :-)

Needs two nested Ifs instead of one Anded together because we only want to test the
value of controls that have such a property. I actually tested the revised code
below.

Dim Cnt As Control

For Each Cnt In Me
If Cnt.Tag = "Lock" Then
If Len(Nz(Cnt, "")) > 0 Then Cnt.Locked = True
End If
Next Cnt
 
Rick,
Again thank you very much for sharing your expertise
with others. That worked exactly as had wanted it to work.
God bless you
Andy
-----Original Message-----


Sorry. That's the problem with Air Code :-)

Needs two nested Ifs instead of one Anded together
because we only want to test the
 
It seems that I got the code back to front - it says true where it should
say false and vice versa. Anyway, it looks like you've managed to solve your
problem.
 
Back
Top