Solved

Using OpenArgs with DoCmd.OpenReport

Posted on 2004-10-20
7
6,134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

734 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