I have a base Query that pulls in data to be used in multiple queries.
Select
ClientActivities.FacilityID
,Facility.FacilityName
,ClientActivities.ClientID
,ClientActivities.ActivityID
,ClientActivities.ActivityDate
From
ClientActivities
Inner Join
Facility
on
ClientActivities.FacilityID = FAcility.FacilityID
Where
ClientActivities.ActivityDate Between [StartDate] and [EndDate]
This feeds two other Queries.
Select
FacilityName
,Count(ClientID)
From
BaseQuery
and
Select
ActivityID
,Count(ClientID)
From
BaseQuery
When I put them both on a single report as subreports- it asks me for the StartDate and EndDate twice. I would like for it to ask only once. Any suggestions on how this can be done? While keeping it simple as once I turn this over to the user I will be leaving and the extent of their Access training is one college class.
Thanks,
Set up a form to run the report from...
Create a form named "frmReports" that contains two text boxes and a button.
Name the text boxes "txtStartDate" and "txtEndDate".
In the queries, put the fully qualified names of the text boxes on the form into the criteria section of the queries. For example: Forms![frmReports]![txtStartDate] and Forms![frmReports]![txtEndDate]
Behind the button click event, place the following code...
DoCmd.OpenReport "ReportName"
To run the report...
Open the form "frmReports".
Enter the beginning and ending dates into the text boxes.
Click the button you created.
Related
Here's the crux of the question, I have 26 compliance queries to run, in a previous question it was suggested that I should filter a single query, or two, on a single report. I like this idea, and have rewritten the query to pull all available data from all the fields, this query works fine. The report will work fine as well, as it does with a model query that I had coded up beforehand. What I would like to do is this:
The end user is being given an interface in access that is locked down, I want them to click a button, and that button will run the query and send to the text box just the field that is called for.
I have tried doing this through VB using the where clause and aliasing the column being called, this did not work at all. I have the report currently pulling the correct data, but not displaying the dates along side it. But it is filtering correctly aside from that.
So what needs to happen is this : Button click : Query runs, and is filtered for "Compliance Issue 1" and puts the dates in "Compliance Issue 1" in the text box on the report.
Right now... I get a list of names, the correct list of names, but an empty column.
I have tried using OpenArgs, but all it did was fill in the date column with "Compliance Issue 1" not the actual data in that column.
Is what I am trying to do even possible in access, and if so does someone have a reference or suggested starting point.
My background : 6 Months of python coding, 3 months of SQL , and some limited access from 20 years ago.
As noted, using the filter of the openreport is without question the way to go (one would not write a whole bunch of different queries - you can send/have any filter for that report - you can EVEN use a sub query in the filter that you send to the report.
As for displaying values in the report that are not from "rows" of data?
There are two approaches that work quite well.
First up, is you have that launcher form. This of course allows the user to select critrea - maybe even some nice combob boxes. These selections take care and you build up the filter in code that you pass to the report.
As for text boxes to be filled out from that form and inclluded in the report?
If they are static values from the report (say filter options, or even just a notes box that you could type in some text? To display such values in textboxes on the report?
You can directly set the text box data source (in the designer) to the report propter form like this:
=(forms!MyPromptForm!notes)
So, any value you shove into text boxes on the report prompt form can thus be displayed in any text box on the report with the above type of expression. And it does not even take code to achieve this goal. So, you could say with above enter some notes into that text box, and thus on the report, whatever you typed into that text box will now show up in the report. You just drop in a text box onto the report, and set the data source of the text box to the above expression that references the form with the values we want from that form.
The next approach, and I often use this in the case that some value/expression/calculation has to occur for each row. In this case, you can use the reports on-detail format event. This allows you to run code for EACH row of data.
You are free to run ANY code in that event - and that includes after running such code to set a text box in the reports detail section.
So, say the query only had the Hotel ID (PK). This is a lame example, but you could then write this code in the on-format event of the reports detail section.
dim strSQL as string
dim rst as DAO.RecordSet
strSQL = "SELECT HotelName from tblHotels where ID = " & me.HotelID
set rst = CurrentDb.OpenRecordSet(strSQL)
me.HotelName = rst!HotelName
rst.Close
So in above, we assume that a row text box is called HotelID, and then in code we build a whole sql query from scratch, pulled the row data from a table, and then SHOVE/SET the value of the un-bound text box called hotelName.
As noted, the above is a simple example, but we are free to run any code we want, pull any data we want, and set the value of ANY text box for the given detail section ONE row of values.
So, above shows two approaches. The first approach is code free - and you can put forms! expression directly into the report, and the values from that report prompt form will thus show up directly in the report. However, if you need VBA code to run for each row, pull values, walk the dog, and THEN set a text box on that one details row of data, then you are as above shows free to write procedural code in the report that fires + runs for each row of data - and that means you can quite much do anything you want in terms of running code. I mean, even that on detail format event COULD pull values from your report prompt form, but as the 1st example shows, you can shove in forms! expression directly into a text box - and those forms! expressions can be values from a existing form that is open before the report is launched.
I'm trying to construct a report in SSRS and I would like to know if instead of using a multiple selection drop down box to search for a particular set of serial numbers, I can give users the ability to manually enter multiple serial numbers of their choice into a text box.
The list of serial numbers in the particular data set is quite large, so with a drop down user would be scrolling through thousands of serial numbers, as opposed to just typing in serial numbers of interest.
You can do this using a parameter
Add Parameter
In the general properties amend the data type and check Allow Multiple values
Click OK
Right click on your data set query
Left click DataSet Properties
Left click Parameters
Add the parameter you created in 1 above - preceded by #
Click on fx
in the expression dialog key =SPLIT(JOIN(Parameters!.Value,","),",")
Click OK
Click OK
Amend your dataset query to include where something in(#)
Save the amended query
Preview the report
A parameter box will appear
Click on the drop down
Enter a comma separated list of serial numbers
Click on view report
Using adventureworks added a parameter #soid
The split statement is
=SPLIT(JOIN(Parameters!SOID.Value,","),",")
The dataset query is
SELECT SalesOrderID, RevisionNumber, OrderDate, DueDate, ShipDate, Status, n OnlineOrderFlag, SalesOrderNumber, PurchaseOrderNumber, AccountNumber, CustomerID, SalesPersonID, TerritoryID, BillToAddressID, ShipToAddressID, ShipMethodID, CreditCardID, CreditCardApprovalCode, CurrencyRateID, SubTotal, TaxAmt, Freight, TotalDue, Comment, rowguid, ModifiedDate
FROM Sales.SalesOrderHeader WHERE SalesOrderID in (#SOID)
I am new to Access 2013 and would like to create a form that allows users to interactively enter search parameters and see the results listed on the same form as multiple items or a data sheet.
This would work like a search on a web page:
Users will enter search criteria and click a search button. A data grid will display the results. Each time the user re-enters the search criteria, the data grid will be reloaded with the query results. It is important that the user not be required to launch one form to enter the criteria and see the results on another form. All should be done on the same form.
My questions are:
If I use VBA to handle the click event and perform the query, is it possible to programmatically set the control source of a data sheet or multiple items to the new query results?
The method that I used to create a dynamic search form is:
Create an Access Form to prompt for search paramaters. Mine consisted of two text boxes with format set to general date. (I want to list all rows between a start and end date), an unbound list box for the results and a command button to execute the search.
Create an Access Query that uses a Criteria setting that references the starting and ending text boxes on the search form. The field name I want to use is named EventDate. In the QBE, I set the Criteria entry for the EventDate field to:
Between [Forms]![frmSimpleSearch]![txtStartDate] And [Forms]![frmSimpleSearch]![txtEndingEventDate]
For the Click event of the Search button, I use the following code:
Private Sub cmdSearch_Click()
' Search for all events between the start and end date
lstResults.RowSource = "qryEventsInDateRange"
lstResults.Requery
End Sub
I currently have a form which contains a seperate combo box that is related to each table I have created.
These include:
- Business Process Area
- Title
- ReportDescription
- ProcessChain
- MultiProvider
- InfoProvider
I'm having multiple issues, but for now I'll just narrow it down to the one.
I want the form to autofill if you select a lower combo box, so for example if you select a Report Description it will fill Title and Business Process Area. I am using DLookup to do this currently and this is working fine. The issue occurs further down the form.
There are many-to-many relationships between ReportDescription and ProcessChain as well as between ProcessChain and MultiProvider. So currently you can select a MultiProvider, and it will just select the first ProcessChain and keep filling the form from there.
My Current DLookup code on my bottom combo box is:
If IsNull(cmbMultiProvider) Then
cmbMultiProvider = DLookup("MultiProviderID", "MultiProvider", "MultiProviderID =" & Me.cmbInfoProvider.Column(2))
End If
If IsNull(cmbProcessChain) Then
cmbProcessChain = DLookup("ProcessChainID", "ProcessChainMultiProvider", "ProcessChainID =" & Me.cmbMultiProvider.Column(2))
End If
If IsNull(cmbReportDesc) Then
cmbReportDesc = DLookup("ReportID", "ReportDescription", "ReportID =" & Me.cmbProcessChain.Column(2))
End If
And so fourth.
So I would like to replace these DLookup statements with something that will stop at the combo box if the selection below relates to multiple of the field above, as in if a MultiProvider selected in a combo box relates to many Process Chains then the combo box will drop down and only contain the related fields.
Thank you in advance for any help.
So you're going "backwards" up the cascading combos? That is, in most cases you would select these items in descending order, but you're moving up in Ascending order. For example, if you wanted to drill down to an automobile, you generally first select the Year, then the Make, then the Model, etc etc.
Instead, you want to select the Make, and have the Model auto-populate (assuming there is only one Make for that specific Model), and then have the Year left blank (since there could be several Years for a Make and Model).
If so, can you tell us more about your data structure? How are Report Description, Process Chain and MultiProvider related in your tables?
I have an Access 2003 MDB where I would like to present a small form for the user to input two parameters "Start Date" and "End Date". Thanks to another Stack Overflow user ("Kevin Ross"), I learned how to embed the form control directly in the query that is used by the report I would like to display.
SELECT q1.CasesAssigned, q2.WarningsIssued
FROM
(SELECT COUNT(*) AS CasesAssigned
FROM vwCaseDetail
WHERE DateAssigned Between [Forms]![frmReporting]![txtStartDate]
AND [Forms]![frmReporting]![txtEndDate]) as q1,
(SELECT COUNT(*) AS WarningsIssued
FROM vwWarningDetail
WHERE DateIssued Between [Forms]![frmReporting]![txtStartDate]
AND [Forms]![frmReporting]![txtEndDate]) as q2
I have tried two different ways to open the report and pass the users input:
After the user enters parameters I call DoCmd.OpenReport "myReport", acViewPreview. The problem here is that the reports opens and close so fast I never even see it. Ideally I would like to close the input collection form and then open the report.
Inside the Report_Open event I have code that opens the form that collect the users input. The input collection form opens, however I still get prompted by the report to enter in the two parameters. The report does not seem to be gathering the parameters from the input collection form.
Any suggestions on the proper way to pass data collected on a form to a report? Thank you.
Well,
The problem should be the logic of what your wantig. Why do you want a report calling a form? Why not a form in wich you fulfill the parameters then call the report?
You can perform your requisites in this way:
Create a form containing the fields corresponding to your desired parameters (Eg two textboxes called Param1 and Param2, in a form called Form1)
Create a query that retrieves the data for your report, referencing, in the conditions field, the parameters in the form (In the example, [Forms]![Form1]![Param1] and [Forms]![Form1]![Param2]). Also, right clik on a empty space of query builder and select "parameters". Inform all the parameters (with the entire strings [Forms]![Form1]![Param1] and [Forms]![Form1]![Param2]) with the correct data type. Let's call this query Query1
Create a report based on Query1. Lets call this report as Report1
Back to Form1, create a button (use the Wizard, its faster) for calling Report1.
Execute the Form1, in runtime fill the textboxes with the desired parameters then click the button. Make sure that you have data in your tables wich corresponds the Query.
In the other parts of your application, instead you call Report1 directly, call the Form1 that will manage Report1 querying and showing.