Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6479
  • Last Modified:

Using OpenArgs with DoCmd.OpenReport

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
David_Mack2004
Asked:
David_Mack2004
  • 3
  • 2
1 Solution
 
Bat17Commented:
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
 
David_Mack2004Author Commented:
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
 
David_Mack2004Author Commented:
Can anybody help with this.  I have upped the points available.
0
 
Bat17Commented:
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
 
Bat17Commented:
Also you will need to adjust the "[pLNO] " field to whatever it is called in the report

Peter
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now