View Single Post
  #8  
Old January 9th, 2008, 05:13 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default locking a field in a form

There is no current event for a control, only the form. It fires each time
you change records.
txt is a naming convention I use to say "this is a text box control" For
example, my combo boxes always start with cbo, command buttons with cmd, etc.
So if your control name is not exactly txtTitleOfArticle it is a naming
problem. It should be exactly what the name of the control is in the Name
property of the properties dialog for that control.
--
Dave Hargis, Microsoft Access MVP


"Debbie S." wrote:

This is exactly what is in the code builder in the current event ("on
current") of the form wrote:

Private Sub Form_Current()
With Me
If .NewRecord Then
.txtTitleOfArticle.Enabled = True
.txtTitleOfArticle.Locked = False
ElseIf IsNull(.txtTitleOfArticle) Then
.txtTitleOfArticle.Enabled = True
.txtTitleOfArticle.Locked = False
Else
.txtTitleOfArticle.Enabled = False
.txtTitleOfArticle.Locked = True
End If
End With

End Sub

What does txt refer to--does that mean text box? Should this code be in the
current event of the text box or the current event of the form?
"Klatuu" wrote:

Did you include the With / End with?
The code as posted should work.
names in Access are not case sensitive, so that would not make a difference.
--
Dave Hargis, Microsoft Access MVP


"Debbie S." wrote:

I did put the actual name of the control, I just did not want to post the
name of the control here. It is the actual name of the control. I checked the
spelling and case (upper/lower). I had to change one letter to upper case
that I had mistakenly written as lower case. I still got the same error.

"Klatuu" wrote:

No, it needs to be the actual name of the control.
--
Dave Hargis, Microsoft Access MVP


"Debbie S." wrote:

Thank you for your quick response. I just tried this, and I got an error
message:

Compile Error: Method or data member not found

It was highlighting the name of the control I had substituted for
".txtsomecontrol" in your code. I substitued as follows: .txtmycontrolnamehere

Is that the correct way to do it?

Thanks again,
Debbie

"Klatuu" wrote:

Yes, use the form's Current event:

With Me
If .NewRecord Then
.txtSomeControl.Enabled = True
.txtSomeControl.Locked = False
ElseIf IsNull(.txtSomeControl) Then
.txtSomeControl.Enabled = True
.txtSomeControl.Locked = False
Else
.txtSomeControl.Enabled = False
.txtSomeControl.Locked = True
End If
End With

It will unlock the control for new records and for existing records where no
entry has been made and Lock it for exiting records where a value exits.
--
Dave Hargis, Microsoft Access MVP


"Debbie S." wrote:

Hello,

I want to be able to lock a field but still allow the user to enter NEW data
into the field in the form. (In other words, allow users to enter new data
into a particular field of a form but not change existing data in that
field). If I lock the field in the properties sheet, the data can't be
edited, which is good, but you can't enter new data either, which defeats the
purpose of the form. Is there a way to do this?

Thanks,
Debbie