A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

locking a field in a form



 
 
Thread Tools Display Modes
  #1  
Old January 9th, 2008, 04:26 PM posted to microsoft.public.access.forms
Debbie S.[_2_]
external usenet poster
 
Posts: 67
Default locking a field in a form

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
  #2  
Old January 9th, 2008, 05:06 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default locking a field in a form

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

  #3  
Old January 9th, 2008, 05:44 PM posted to microsoft.public.access.forms
Debbie S.[_2_]
external usenet poster
 
Posts: 67
Default locking a field in a form

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

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

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

  #5  
Old January 9th, 2008, 05:50 PM posted to microsoft.public.access.forms
Debbie S.[_2_]
external usenet poster
 
Posts: 67
Default locking a field in a form

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

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

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

  #7  
Old January 9th, 2008, 06:06 PM posted to microsoft.public.access.forms
Debbie S.[_2_]
external usenet poster
 
Posts: 67
Default locking a field in a form

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

  #8  
Old January 9th, 2008, 06: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

  #9  
Old January 9th, 2008, 06:48 PM posted to microsoft.public.access.forms
Debbie S.[_2_]
external usenet poster
 
Posts: 67
Default locking a field in a form


Oh! Well that explains it then. I'll try it without the txt and see what
happens.
Thank you!
Debbie
"Klatuu" wrote:

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

  #10  
Old January 9th, 2008, 08:25 PM posted to microsoft.public.access.forms
Debbie S.[_2_]
external usenet poster
 
Posts: 67
Default locking a field in a form

It works perfectly! Thank you so much.

"Klatuu" wrote:

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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.