Link to home
Create AccountLog in
Avatar of Computer_Support_Norwich
Computer_Support_NorwichFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Issue with openargs, run time error 2448. You can't assign a value to this object.

I'm probably doing this the wrong way, but here goes.

I have a form 'frmCustomer'.
On the form is a button to open 'frmContactPopup' in order to create a new contact for a given customer.

So, the code on the button is:

DoCmd.OpenForm "frmContactPopup", acNormal, , , acFormAdd, , OpenArgs:=Me.customerid.Value

And the code on the frmContactPopup is:

  If Me.NewRecord Then
     Me.customerid.Value = Me.OpenArgs
  End If

But the frmContactPopup never gets populated with the customerid.

The error is:

Run-time error 2448 - You can't assign a value to this object.

I think this may be the wrong approach...? How do I load a new form, to create a new record, based upon data in this 'parent' form.

For display related reasons I would rather not use a subform which is one solution.
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

"Run-time error 2448 - You can't assign a value to this object."

What is the datatype of the customerid  field that is displayed in frmContactPopup.
You can set default value for field customerid on form frmContactPopup to
Forms!frmCustomer.customerid
and new records will have this value
Use builder for proper syntax.
openargs should be a bucket of variables,

you might need to assign it to a variable in openargs

OpenArgs.CustomerID:=Me.customerid.Value

http://msdn.microsoft.com/en-us/library/office/aa160845(v=office.10).aspx
Avatar of Computer_Support_Norwich

ASKER

Thanks all. I'll look at these right now.
The record source for frmContactPopup WAS coming from the query builder, rather than a proper query or table. I have changed this so the data comes direct from a proper query. I have no idea if this will help, but it seems like the right thing to do.

peter57r
========
customerid is from an autonumber field.

als315
======
That's a fair point, but I use this frmContactPopup when looking at existing comntacts, not just for adding new ones, so not sure if that would work?


rg20
====
I get a compile error (Expected: end of statement when changing my button code to:

DoCmd.OpenForm "frmContactPopup", acNormal, , , acFormAdd, , OpenArgs.CustomerID:=Me.customerid.Value

I have attached a copy of the DB for reference.
database.zip
ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
"customerid is from an autonumber field."

Then you cannot assign a value to it.  

I suspect al315 may have the answer above.
Ahhhhhhh. Thanks for the feedback will try this out later today.
als315... worked a treat, thanks!

I really appreciate everybodys time on this. I wish it were as obvious to me as it is to you...
Thanks to everyone for their input. I know it was a 'quick one' for you, but saved me a lot of hassle.