Solved

Using OpenArgs with DoCmd.OpenReport

Posted on 2004-10-20
7
5,842 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now