Solved

Using OpenArgs with DoCmd.OpenReport

Posted on 2004-10-20
7
6,099 Views
Last Modified: 2012-06-21
MS Access 2002.
I have a report based on a query that takes parameters.  The query currently has direct references to form controls in the SQL.  I want to change these to general query parameters to be passed to the query (indirectly via the report) so I can call this report from other forms.
I am trying to use the OpenArgs property in the following way:

DoCmd.OpenReport "rptDailyProductionReport", acPreview, , , , "[pLNO]:='" & cboLine.value & "'"


where pLNO is the parameter within the query and cboLine.value is the value I am trying to pass into the parameter.
The above code is not working (and I have tried many variations of this) but I am constantly getting the input box asking me to provide a value for pLNO.

Also I have multiple parameters to pass so could any code snippets solving this problem please take this into consideration.

0
Comment
Question by:David_Mack2004
  • 3
  • 2
7 Comments
 
LVL 9

Expert Comment

by:Bat17
ID: 12366782
Rather than trying to do it with OpenArgs I think that you will be better doing it by passing it a Where condition. This is the same as the Where condition in a SQL for a query but without the word where. You will need to remove the parameters from your query, but that is ok as the Where Condition replaces them. When you add the criteria to your condition you have to remember to wrap text in quotes. Here is an example passing a text criterion and a number criterion to a report.

Dim strfilter As String
Dim strTextCriteria As String
Dim lngNumberCriteria As Long
strTextCriteria = "xyz"
lngNumberCriteria = 123456

strfilter = "((([MyTable].[MyTextField])='" & strTextCriteria & "') AND (([MyTable].[MyNumberField])> " & lngNumberCriteria & "));"
DoCmd.OpenReport "rptDailyProductionReport", acPreview, , strfilter

HTH

Peter

0
 

Author Comment

by:David_Mack2004
ID: 12375879
Thanks Peter but this query is based on other queries and is used in other parts of the application.  I would prefer to use it and leave the parameters alone.  I had thought of using the filter functionality but decided against for the above reasons.  Are you saying that the OpenArgs property does not work?  Does anybody else have information on this?
0
 

Author Comment

by:David_Mack2004
ID: 12417363
Can anybody help with this.  I have upped the points available.
0
 
LVL 9

Accepted Solution

by:
Bat17 earned 150 total points
ID: 12418886
It looks as if you should be able to achieve this using the reports filter mechanism.

Pass the open arguments to the report with just the cbo value
DoCmd.OpenReport "rptDailyProductionReport", acPreview, , , , cboLine.value

In the on open event of the form have:-

Sub Report_Open(Cancel As Integer)
     If Not IsNull(Me.OpenArgs) Then
        Me.Filter = "[pLNO] = " & Me.OpenArgs
        Me.FilterOn = True
    End If
End Sub

If cboLine.value is a string you will need to tweak the filter line to
Me.Filter = "[pLNO] = '" & Me.OpenArgs & "'"

I have not had a chance to test this but it should work.

HTH

Peter
0
 
LVL 9

Expert Comment

by:Bat17
ID: 12418888
Also you will need to adjust the "[pLNO] " field to whatever it is called in the report

Peter
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question