locked property

Status
Not open for further replies.

alexlds

Registered User.
Local time
Today, 17:21
Joined
May 28, 2012
Messages
71
I am trying to run this in the oncurrent procedure for Form1 in Access 2007

If Not IsNull(Forms![form1]![COMMISSION]) Then
Forms![form1]![COMMISSION].Locked = True
Else
Forms![form1]![COMMISSION].Locked = False
End If

I get error 438 Object dosnt support this method or property

cant figure out why. What am I doing wrong?? It dosnt seem to work in beforeupdate either. Can anyone help? Im sure its probably something obvious
 
Code running on Form1 can use the Me keyword to refer to itself, which simplifies things to..
Code:
If Not IsNull(me.COMMISSION) Then
  Me.COMMISSION.Locked = True
Else
  Me.COMMISSION.Locked = False
End If
And since IsNull() returns a boolean and the locked property is a boolean, they are said to 'vary directly' with each other and you can do...
Code:
Me.Commission.Locked = Not IsNull(Me.Commission)
...and if you still get the error, then probably Form1 does not contain a control called Commission.
hth
Mark
 
something weird going on

i had tried the long form instead of the Me. just to see if that was the cause of the prob

when I try it in the OnCurrent for the form there are now no error messages - but it dosnt work - i can still edit the field from the form after there is data in it.

If I put the code in the Before Update for the field I get - error method or data member not found.

Im running this in a test db with just one table and one form and 5 records just to see if I can get this code working.

Ive tried compact & repair and also run check for disk errors in windows 7 thinking that might be it, but its still not working

All I want to do is to stop data being changed in a field once it has been entered
 
what type of filed is [commission]

is it a label? you cannot lock labels.
 
commission is just a field (text box) on the form linked to a table - its not a label
 
What is highlighted when the error occurs?

Also, why are you trying to get in on the "On Current" event instead of the "On Open" Event?
 
it is the .Locked= bit that is highlighted

only from what Ive read on the forums which seem to indicate that I need to put it in the OnCurrent for the form or in the Before Update for the control.

When browsing through records with the form all Im trying to do is to prevent existing entries in that field being changed
 
Are you using your own buttons or the built in record navigators?
 
On the "On Current" event, instead of using Not Null try the following:

Code:
If Nz(Me.COMMISSION.Value,"") <> Then
  Me.COMMISSION.Locked = True
Else
  Me.COMMISSION.Locked = False
End If
I created a test database and inserted this code and it worked. If it doesn't check to make sure that the name of the control (the text box) is not mispelled or something like that.
 
apologies for querying this, but when I paste in the code everything before and including the Then appears in red font . . .

Im using my own buttons not the built in record navigators
 
As I said something weird is going on - I still get the same error message with .locked= highlighted.

Im going to delete the db and make a completely new one to test the code - in case there is some sort of hidden glitch in the one im using

Ill see how I get on and hopefully wont need to come back - but you never know your luck haha
 
Im still getting the same error message with the ".locked=" bit highlighted.

If it works on yours (office 2007??) then I can only conclude that there is something wrong with my copy of access.

Ive tried all the local compact repair troubleshoot and checkdisk options etc but no luck. Im due to upgrade to office 2010 in a few days anyway - and hoping (????) that wont be too much of a jump as far as access is concerned.

the error message I get is the same if I use either the IsNull or the Nz approach with the .locked= bit being highlighted in both cases

If anyone has any comments / clues on this problem Id be interested. And thanks for all your help

Oh - and can anyone recommend a decent beginner / intermediate book on access ??

Thanks again
 
OK to simplify even further ive done the following test

I have a text box called commission on a form

I have put a button on the form that runs this code

Private Sub Command6_Click()
Me.commission.Locked = True
End Sub

When I click the button I get error method or data mamber not found - and the ".Locked=True" part of the code is then highlighted

Ive even turned off my antivirus to see if that was somehow messing wiith the code but it wasnt.

Any ideas??
 
There are two possibilities,
1) there is not a control on the form called 'commission', or
2) the control called 'commission' is not a textbox.
 
Status
Not open for further replies.

Users who are viewing this thread

Back
Top Bottom