473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Use IF-THEN to change query parameters for a report

I have a form with a series of check boxes and combo boxes to change report criteria. Based on the user's selection, I need 1 - 17 reports to print with different criteria from the same 5 queries. Each query has been made into a sub-report. I cannot seem to figure out how to get the scenarios to influence the query parameters. For sake of space, I have only included 2 queries worth below.

[Private Sub cmdPrint_Click()
Dim dbs As DAO.Database
Dim qdf1 As DAO.QueryDef
Dim qdf2 As DAO.QueryDef

Dim stReport As String
Set dbs = CurrentDb
Set qdf1 = dbs.QueryDefs("qrySlurryPumps_Pump")
Set qdf2 = dbs.QueryDefs("qrySlurryPumps_HandAdd")

stReport = "rptPumpingRecord"

If Me.Check_L1 = True And Me.Check_L1HAS = False And Me.Check_L1HAP = False And Me.Check_L1OTC = True Then
qdf1.Parameters("PumpDate").Value = Forms![frmPrint]![ProductionDate]
qdf1.Parameters("SlurryTank.Value").Value = "Line 1"
qdf1.Execute
qdf1.Close

qdf2.Parameters("PumpDate").Value = Forms![frmPrint]![ProductionDate]
qdf2.Parameters("Hand_Add.Value").Value = "0"
qdf2.Execute
qdf2.Close
DoCmd.OpenReport stReport, acViewPreview

End If]
Mar 17 '17 #1
3 972
PhilOfWalton
1,430 Expert 1GB
I suggest a totally different approach.

Use the DoCmd.OpenReport method and build the WHERE filter from the criteria found in your form.

Assuming the print button is on your form, you would have things like

Expand|Select|Wrap|Line Numbers
  1.    Dim WhereClause as String
  2.  
  3.    WhereClause = "PumpDate = #" & ProductionDate & "#"
  4.    WhereClause = WhereClause & " AND "SluryTankValue = " & Chr$(34) & "Line 1" & Chr$(34)
  5.  
  6.    DoCmd.OpenReport stReport, acViewPreview, , WhereClause 
  7.  
Phil
Mar 19 '17 #2
Would this work where I have to print the same report multiple times with different criteria based on the selections of the form?
Mar 20 '17 #3
PhilOfWalton
1,430 Expert 1GB
Yes, because you build different WHERE clauses depending on the information required in your reports. The report isn't "Created" until it has been supplied with the WHERE information.

It won't work if you need different grouping & sorting in your reports though

Phil
Mar 20 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
2
by: amith.srinivas | last post by:
Hi all, From a word macro in VBA, I am trying to create a report in access DB. The report is based on a query with a parameter. I am using Set rpt = Application.CreateReport rpt.RecordSource =...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
4
by: amorphous999 | last post by:
I am running Access 2002. I have some reports I would like to be able to run from VBA or interactively. The reports use queries with parameters. When the user runs the report, the parameter...
6
by: sunil | last post by:
I have a button named Button1, and I wrote an event handler for the OnClick event. protected void Button1_Click(object sender, System.EventArgs e) { this.Response.Redirect("Default.aspx?q=" +...
5
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
2
by: sara | last post by:
I am helping a non-profit track their elder clients and care given to the clients. The organization would like a report that shows various info on ALL clients, such as: # in each town, # and...
2
by: raaman rai | last post by:
i have 3 drop dropdown box which is used for searching my database. Either one of them can be selected to perform the search but if none of them is selected it will give an error. Well in reference...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.