Pass an argument to a report, both programmatically and not

G

Guest

I have a report that takes an argument "OrderId". When the user opens it from
the access client file, he is prompted for it. That's ok

When I open it from my C# program with the DoCmd.OpenReport command, I can
already know the OrderId. I want to pass it as an argument.
The problem is that a solution with OpenArgs I saw assumes that the user
will never directly open the report from the database. I want to keep the
current behaviour when I open it from the database, but be able to give an
(optional) argument otherwise.

Any suggestion? (I am very new to programming reports)
Thanks in advance!
 
M

Marshall Barton

tec-goblin said:
I have a report that takes an argument "OrderId". When the user opens it from
the access client file, he is prompted for it. That's ok

When I open it from my C# program with the DoCmd.OpenReport command, I can
already know the OrderId. I want to pass it as an argument.
The problem is that a solution with OpenArgs I saw assumes that the user
will never directly open the report from the database. I want to keep the
current behaviour when I open it from the database, but be able to give an
(optional) argument otherwise.


Using OpenArgs conditionally is simple. Just have the
report ignore it when it's Null. Simple example code in the
report's Open event procedure:

If Not IsNull(Me.OpenArgs) Then
Me.Filter = "somefield = " & Me.OpenArgs
Else
Me.Filter = "somefield = " & InputBox("somefield")
End If
Me.FilterOn = True

Be sure to remove the prompt criteria from the report's
record source query.
 

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