OPENARGS is always null (1 Viewer)

bbulla

I'd rather be golfing
Local time
Today, 12:29
Joined
Feb 11, 2005
Messages
101
Hi,

I'm trying to pass a value from a form to a report. In my report I do this when a button is clicked:

DoCmd.OpenReport stDocName, acPreview, , , , "2008"

On the report in the _Open event, I do this:

Dim dateString As String
dateString = Me.OpenArgs

I get an error saying 'Invalid use of Null', and through debugging I can see that Me.OpenArgs is null.

I don't understand what I am doing wrong. Any ideas??
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:29
Joined
Aug 30, 2003
Messages
36,139
I believe you have it in the wrong position. Try one more comma.
 

boblarson

Smeghead
Local time
Today, 09:29
Joined
Jan 12, 2001
Messages
32,059
I believe you have it in the wrong position. Try one more comma.

Paul:

I copied and pasted what they have there into my Immediate window and checked - the commas are correct.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:29
Joined
Aug 30, 2003
Messages
36,139
Oops; I was overly focused on the 4 together and missed the one before acPreview. Sorry about that.
 

boblarson

Smeghead
Local time
Today, 09:29
Joined
Jan 12, 2001
Messages
32,059
The only think I can think of is if they have somewhere declared a variable for OpenArgs which is overloading it.

bbulla:

You haven't put in something like this somewhere have you?

Dim OpenArgs As ...

or

Private OpenArgs As ...

or

Public OpenArgs As ...


If you have, you shouldn't. If you haven't, perhaps you can upload a copy of your database (with bogus data of course) so we can do some tests.

It might also be a corrupt form or report which is causing it to not work properly. I would guess on the side of corrupt report in this case. Perhaps if you do a quick test and recreate the report in a down and dirty fashion just so you can see if the form opens it right and the OpenArgs is populated.
 

bbulla

I'd rather be golfing
Local time
Today, 12:29
Joined
Feb 11, 2005
Messages
101
OK, so here is the problem. If you had the report open in Design View, you cannot reference the OpenArgs. The report has to be completely closed, and then opened via the form for this to work.

Strange, but true. I guess it's just one of those MS Access 'things'.

Thanks,
 

boblarson

Smeghead
Local time
Today, 09:29
Joined
Jan 12, 2001
Messages
32,059
Makes sense. So you had the form open in Design view?

So you could use a global variable instead and set the value prior to the code opening the report and in the open event of the report use it instead.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:29
Joined
Aug 30, 2003
Messages
36,139
I wouldn't call it strange. When you went to design view from preview, the report technically closed, which caused it to lose the OpenArgs value. Add this to the On Close event:

MsgBox "closing"

Open the report via your code and then switch it to design mode. You'll get that message.
 

Users who are viewing this thread

Top Bottom