Connecting Tech Pros Worldwide Forums | Help | Site Map

ctl.Locked property error through VBA code.

Newbie
 
Join Date: Dec 2007
Posts: 5
#1: Dec 26 '07
Hello. I am using MS Access 2003 with XP/pro. I have a form that has the following properties set through the property sheet:

form: AllowAdditions = False
CartridgeID field: Locked = True

The AllowAdditions property is set so that the user can navigate through the records but not be able to begin a new record without clicking the New Record button. The ID field is locked so the user cannot change that field, while still being able to update/edit the rest of the record.

When the user clicks on the New Record button, I want the AllowAdditions property set to True and the Locked property for the ID field set to False.

I have tried this two ways through VBA code:

Expand|Select|Wrap|Line Numbers
  1. '1:
  2. Me.AllowAdditions = True
  3. Me.DataEntry = True
  4. Me!CartridgeID.Locked = False
  5.  
  6. '2:
  7. Me.AllowAdditions = True
  8. DoCmd.GoToRecord , , acNewRec
  9. Me!CartridgeID.Locked = False
  10.  
According to the Access help file and the Access website, either of these should work. However, I am getting the following error message every time it hits the Me!CartridgeID.Locked = False line of code:

"Run time error 438: Object doesn't support this property or method."

I am using the exact same syntax as is displayed in the examples from the help files and I do not understand why I am getting this error.

Any assistance you can provide will be greatly appreciated.

missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,002
#2: Dec 26 '07

re: ctl.Locked property error through VBA code.


First off, I'd trash the first code. DataEntry = True causes Access to create an empty recordset, and since you already have a recordset open based on your table or query, I wouldn't open a second one.

I'm guessing that CartridgeID is a required field, and maybe Access is balking because when a new record is invoked, it's locked. First thing I'd try is to place the unlocking code before going to a new record, and see if that solves the problem. Access is notorious for not actually hiliting the line causing the problem; it often hilites the immediately preceding line instead.
Expand|Select|Wrap|Line Numbers
  1.   Me.AllowAdditions = True
  2.   Me!CartridgeID.Locked = False
  3.  DoCmd.GoToRecord , , acNewRec
  4.  
Welcome to TheScripts!

Linq ;0)>
Newbie
 
Join Date: Dec 2007
Posts: 5
#3: Dec 27 '07

re: ctl.Locked property error through VBA code.


Thank you very much!
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,002
#4: Dec 28 '07

re: ctl.Locked property error through VBA code.


So that solved your problem?

Linw ;0)>
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,224
#5: Dec 28 '07

re: ctl.Locked property error through VBA code.


Quote:

Originally Posted by ljstern

Hello. I am using MS Access 2003 with XP/pro. I have a form that has the following properties set through the property sheet:

form: AllowAdditions = False
CartridgeID field: Locked = True

The AllowAdditions property is set so that the user can navigate through the records but not be able to begin a new record without clicking the New Record button. The ID field is locked so the user cannot change that field, while still being able to update/edit the rest of the record.

When the user clicks on the New Record button, I want the AllowAdditions property set to True and the Locked property for the ID field set to False.

I have tried this two ways through VBA code:

Expand|Select|Wrap|Line Numbers
  1. '1:
  2. Me.AllowAdditions = True
  3. Me.DataEntry = True
  4. Me!CartridgeID.Locked = False
  5.  
  6. '2:
  7. Me.AllowAdditions = True
  8. DoCmd.GoToRecord , , acNewRec
  9. Me!CartridgeID.Locked = False
  10.  
According to the Access help file and the Access website, either of these should work. However, I am getting the following error message every time it hits the Me!CartridgeID.Locked = False line of code:

"Run time error 438: Object doesn't support this property or method."

I am using the exact same syntax as is displayed in the examples from the help files and I do not understand why I am getting this error.

Any assistance you can provide will be greatly appreciated.

  1. As linq has suggested, get rid of the DataEntry = True line in the first block of code.
  2. As I see it, there is absolutely no reason why the second block of code should not work, even if [CartridgeID] is required, unless [CartridgeID] refers to a Control that does not support the Locked Property such as a Label. Can this possibly be the case?
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,002
#6: Dec 28 '07

re: ctl.Locked property error through VBA code.


That was the first thing that crossed my mind, too, ADezii, but the line

"The ID field is locked so the user cannot change that field"

made me assume that it was indeed, a textbox. Of course, stranger things have happened!

Linq ;0)>
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,224
#7: Dec 28 '07

re: ctl.Locked property error through VBA code.


Quote:

Originally Posted by missinglinq

That was the first thing that crossed my mind, too, ADezii, but the line

"The ID field is locked so the user cannot change that field"

made me assume that it was indeed, a textbox. Of course, stranger things have happened!

Linq ;0)>

In this business that seems to be the norm (LOL)!
Reply