Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OpenArgs, error 2448, You can't assign a value to this object

63 views
Skip to first unread message

Douglas Buchanan

unread,
Jun 22, 2003, 9:36:53 PM6/22/03
to
Access 2k
How do I open Form1 (acFormAdd) from Form2 passing the OpenArgs, and
set the value of the foreign key to the OpenArgs value? Both are text
datatype.

Here is how I am trying to do it.

Form1
Record Source: Table1

'***** Start of Code in Form1
Private Sub cmdOpenForm2_Click()
DoCmd.OpenForm "Form2", DataMode:=acFormAdd, OpenArgs:=Me!txtPkID
DoCmd.Close
End Sub
'***** End of Code in Form1

Form2
Record Source: Table2

'***** Start of Code in Form2
Private Sub Form_Open(Cancel As Integer)
Me!txtFkID.Value = Me.OpenArgs
End Sub
'***** End of Code in Form2

I get the error# 2448
"You can't assign a value to this object"

I've tried
1.) putting the code in the Load event (no good)
2.) using msgbox or debug to be sure the value is passed to the new
form (it is)
3.) setting focus to the text box before trying to give it the value
(no good)
4.) trying many various other suggestions from this newsgroup from
those having similar problems. (all of them dead ends)

What am I missing?

MacDermott

unread,
Jun 22, 2003, 11:10:16 PM6/22/03
to
The data isn't loaded yet when the Open event fires, so you can't assign a
value to an object yet.
Try running that code in the Form_Load event instead.

HTH
- Turtle

"Douglas Buchanan" <dbuch...@comcast.net> wrote in message
news:dbbb383.03062...@posting.google.com...

Douglas Buchanan

unread,
Jun 23, 2003, 10:43:04 AM6/23/03
to
Thank you for your reply.

I have already tried putting the code in the Load event. It does not
work!

Here is what happens:
Form2 flashes on the screen for about 1/4 second and then is gone! I
receive no error message.

There are no conflicts of in table field datatype or anything else
that I can think of, it just doesn't work!

Note: I understood from Access help said that the Open event was where
the OpenArgs was to be used. - However being ready to try anyting and
seeing some referenced on Google for putting it there (as well as in
the Open event) I went ahead and tried the Load event.

I'm still ready to try anything. Please tell me how I must change my
code to make it work in the Load event or anywhere else for that
matter. (see original post)

Thank you,
Doug


"MacDermott" <macde...@mindspring.com> wrote in message news:<bd5r2o$upf$1...@slb0.atl.mindspring.net>...

Jim Allensworth

unread,
Jun 23, 2003, 11:38:51 AM6/23/03
to
A couple of thoughts.

Is txtFkID on form2 enabled in dataentry mode?

OpenArgs is passed as a text value. Is that what you are dealing with
in the FKID?

Also, I believe that when you open the form it receives focus. So when
you do the DoCmd.Close you are closing the form that you just opened.
Instead try ...
DoCmd.Close acForm, Me.Name

If the value is a long integer try ...
Me.txtFkID = CLng(Me.OpenArgs)

- Jim

On 22 Jun 2003 18:36:53 -0700, dbuch...@comcast.net (Douglas

Douglas Buchanan

unread,
Jun 23, 2003, 11:42:48 PM6/23/03
to
Whalla!! It works. Thanks to both of you for your responses!

For those who encouter this problem in the future...

1.) Thank you Jim Allensworth: The Do.Cmd Close was a major problem. I
did not realize that that was one of the reasons that the form closed
so quickly. It mislead me.(Another reason it kept closing quickly was
that I left some incorrect code in my DoCmd.OpenForm statement left
over from one of my many earlier experimental trys.)

2.) Thank you MacDermott: The code did indeed need to be in the
Form_Load event.
This was the primary cause of my problem.
What mislead me was MS Help. It said the Form_Open event was where to
use the OpenArgs.

MS Help quoted in part here:
"open a form by using the OpenForm method of the DoCmd object, and set
the openargs argument to the desired string expression. The OpenArgs
property setting can then be used in code for the form, such as an
Open event procedure."

You can see the full quote in its context by pressing F1 when the
cursor is on 'OpenArgs' in a code expression. (It is either wrong or I
misunderstood what it was saying.)

The Open event does not work because the controls are not yet loaded.

3.) At one time I thought that the existing table relationship had
something to do with my problem. I had a one-to-many relationship
between Table1 PKID and Table2 FKID and because I could not manually
put the data into the code's target field. It does not mattter, code
*is* allowed to do what a user is not.

Thank you again,
Doug

Jim...@NOTdatacentricsolutions.com (Jim Allensworth) wrote in message news:<3ef71cbc...@netnews.attbi.com>...

0 new messages