You Can't Assign A Value To This Object

A

Alan

Hi, fairly new to this and hope I can get some help. I keep getting "Run-time
error '2448' You can't assign a value to this object" each time the code in
my form runs.

I have a query based on a couple of tables and in turn a form based on this
query. A default value of 16 is assigned to [Sample Size] in a table; on
Form_Open I want the code to run, check the Lot Number value with a range I
specify, then if the value of [Sample Size] is 16 change it to 15 and save
this value back to my table.

If I open the form without code active I can overtype [Sample Size] with any
value I want and this is saved back to my table but I don't want users to do
this so why can't I do it through code? Is my reference to [Sample Size] in
code not correct? Does it need to be Tables!MyTable.[Sample Size] or
something like that because I can't find the syntax that works.

TIA

Private Sub Form_Open(Cancel As Integer)
CheckSampleSize
End Sub

Function CheckSampleSize()
If [Lot Number] >= 300000 And [Lot Number] <= 399999 Then
Select Case [Sample Size]
Case Is = 16
[Sample Size] = 15
End Select
End If
End Function
 
B

BruceM

Form_Open runs once when the form opens. I think it's too early an event
for data validation; in any case the records were saved when the form was
closed, so I can't see that it makes sense to test existing records. If I
understand correctly what you are trying to do the form's After Update event
would be a better place for the function. When you add the function to the
After Update event you need to include the parentheses:
CheckSampleSize()
Also, try specifying that it is a Public (or Private) function:

Public Function CheckSampleSize()
 
A

Alan

OK tried your suggestions. Declaring as Public or Private made no difference.
When I attempt to include parentheses CheckSampleSize() I get "Compile Error
Expected:=". I also moved the function to After Update and didn't get the
previous Run-time error but got a message saying that "You can't save this
record at this time" and the field [Lens Sample Size] didn't update either.
Any more suggestions?

BruceM said:
Form_Open runs once when the form opens. I think it's too early an event
for data validation; in any case the records were saved when the form was
closed, so I can't see that it makes sense to test existing records. If I
understand correctly what you are trying to do the form's After Update event
would be a better place for the function. When you add the function to the
After Update event you need to include the parentheses:
CheckSampleSize()
Also, try specifying that it is a Public (or Private) function:

Public Function CheckSampleSize()


Alan said:
Hi, fairly new to this and hope I can get some help. I keep getting
"Run-time
error '2448' You can't assign a value to this object" each time the code
in
my form runs.

I have a query based on a couple of tables and in turn a form based on
this
query. A default value of 16 is assigned to [Sample Size] in a table; on
Form_Open I want the code to run, check the Lot Number value with a range
I
specify, then if the value of [Sample Size] is 16 change it to 15 and save
this value back to my table.

If I open the form without code active I can overtype [Sample Size] with
any
value I want and this is saved back to my table but I don't want users to
do
this so why can't I do it through code? Is my reference to [Sample Size]
in
code not correct? Does it need to be Tables!MyTable.[Sample Size] or
something like that because I can't find the syntax that works.

TIA

Private Sub Form_Open(Cancel As Integer)
CheckSampleSize
End Sub

Function CheckSampleSize()
If [Lot Number] >= 300000 And [Lot Number] <= 399999 Then
Select Case [Sample Size]
Case Is = 16
[Sample Size] = 15
End Select
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top