Pass an argument to a report, both programmatically and not

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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.
 
Back
Top