Solved

Using OpenArgs with DoCmd.OpenReport

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to not remove leading zeros 9 38
Adding icons to a custom, shortcut menu function 6 41
DSum for Access 6 44
MS accesss using VBA to change a default value 5 28
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 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