OpenArgs Error

S

Sky Warren

Hello All,

I'm using Access 2003 and I'm getting a "Run-time error 13 : Type mismatch"
message from running the following code:


Private Sub Regional_AfterUpdate()

Dim Agent_Name as String

Agent_Name = "John Doe"

DoCmd.OpenReport "Clients", acViewPreview, , , Agent_Name

End Sub

Access is saying the Agent_Name variable in the OpenArgs is not the right
type. How can the OpenArgs be used to pass data to a report?
 
K

Ken Snell [MVP]

You're missing a comma. OpenArgs is the sixth argument, not the fifth:

DoCmd.OpenReport "Clients", acViewPreview, , , , Agent_Name
 
S

Sky Warren

Hello Ken,

Thanks, your absolutely right about that placement. I added the fourth comma
but still continued to get error messages. I read in a different thread that
OpenArgs cannot be used to pass variables to a report, only to a form. It's
OK though, I found a different method to achieve the same thing.

I posted the solution in thread "Report Header Variable" in this forum.
Thanks very much for your response.
 
K

Ken Snell [MVP]

OpenArgs works for reports in ACCESS 2002 and 2003; it won't work in ACCESS
97 and 2000.

So what you read does not apply to your situation.
 
L

Leif

Ken,

I tried it with Access 2003, and it does not seem to work. I coded the
following:

DoCmd.OpenReport "rptQualStat", acViewPreview, , , , "28"

I tried to read it in the report_open event. I also tried the
report_activate. In both cases openargs returns Null.
 
J

Jeff Boyce

Leif

OpenArgs works on Forms, but I don't believe the OpenReport syntax allows
for it. Another approach is to have the report "point at" (refer to) the
form in which you are trying to open the report. You can use the expression
(untested aircode, your syntax may vary):

Forms!frmYourForm!txtYourTextField

to let the report "see" the value.

Or perhaps you could open the report with a "filter" or "where" condition,
which are part of the OpenReport syntax...

--
Good luck

Jeff Boyce
<Access MVP>
 
K

Ken Snell [MVP]

Post the code that you tried to use in the report's Open event (activate
will not be suitable for you in this situation).
 
K

Ken Snell [MVP]

Marshall Barton said:
FYI - OpenArgs for reports was a new feature in AXP.

Yeah.. I posted that exact info a few notes up...Jeff musta not seen it < g
 
L

Leif

Ken,

Now here is an interesting one for you. Openargs does not work for reports
as a positional parameter, but it does work as a named parameter! I got the
idea from seeing someone's post where they used a named parameter. By the
way, I'm using Access 2003 (XP). I'm picking up the parameter in report_open.

This does not work:

DoCmd.OpenReport "rptQualStat", acViewPreview, , , , "28"

But this does work:
DoCmd.OpenReport "rptQualStat", acViewPreview , OpenArgs:="28"

Regards,
Leif
 
K

Ken Snell [MVP]

Interesting is a good word for it. Seems weird... I use OpenArgs parameters
regularly in my ACCESS 2002 reports and do not specify the argument name; I
always do it via the 6th argument in the list.
--

Ken Snell
<MS ACCESS MVP>
 
K

Ken Snell [MVP]

Perhaps the report that you're opening is corrupted. Or perhaps this is a
weird "bug" from having the "Name AutoCorrect" option turned on in the
database.

What indicates to you that the first step doesn't work? Did you read the
value of OpenArgs in the report's Open event? What value do you get? What
code are you running there?
--

Ken Snell
<MS ACCESS MVP>
 
K

keaven

that -is- strange. i have had issues with openargs in the past that
seem to match what was going on here. i never found out why it wasn't
working, but if i closed access completely and reopened it, then my
openargs statements worked just fine. <shrug> go fig.

-keaven

Interesting is a good word for it. Seems weird... I use OpenArgs parameters
regularly in my ACCESS 2002 reports and do not specify the argument name; I
always do it via the 6th argument in the list.

--
-----------------------------------------------------------------------
Keaven Freeman "There's no place like 127.0.0.1"
usenet[@]keaven[.]com ICQ: 35133457
http://www.keaven.com IM: KeavenMJ
"The box said 'Requires Windows 95 or better' ... so I installed Linux"
-----------------------------------------------------------------------
 
S

Sky Warren

Hey Guys,

Sorry for such a late post. Using OpenArgs was a real pain but I got a
workaround from someone else "don't remember who".

What I initially wanted was to have a agents name appear in the header
section of all my reports without hardcoding that name into every report. I
ended up creating a new module with a public function in it which looks like
this:

Public Function AgentFull() As String
AgentFull = "John Doe"
End Function

Then, in the header section of each report is a text box with the following
as the Control Source:

=AgentFull()

Thus, "John Doe" appears in the header of every report. Plus, if I need to
change that name I only need to edit the module that contains the public
function. This works far better than fooling around with OpenArgs, which I
never got to work correctly.

I had problems at first though. I was trying to create the public function
inside the main form, THAT APPROACH WON'T WORK. Once I created the standalone
module and put the function inside, it worked great!!! Trial and error but
this is how we learn ;-)

As always, thanks to all who responded and tried helping another lost amatuer.

-Sky
 
K

Ken Snell [MVP]

I'm assuming that someone pointed out the syntax error in your
DoCmd.OpenReports line?

You posted
DoCmd.OpenReport "Clients", acViewPreview, , , Agent_Name

Should be
DoCmd.OpenReport "Clients", acViewPreview, , , , Agent_Name
 

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

Similar Threads


Top