I have a created two access reports. One is a summary report and the other provides greater detail. There is a common field for each. The summary report is always 1 page printed portrait. The detail report is always printed landscape and can be 1 or more pages. Currently i need to print each report separately and manually match by the common field (employer number). The print sort is also differs for both. The summary report has a sequence number. The detail report does not and uses the employer number as the sort index.
What i would like to figure out is the ability to print these reports out together. Summary report and then its related detail report... Summary report and its detail report, etc.
Basically you need a VBA procedure that will open a recordset to allow you to loop through the employee numbers. The main part of the procedure will look something like this:
Set rsEmployees = CurrentDb.OpenRecordset "select EmpNo from Employees order by EmpNo"
Do While Not rsEmployees.EOF
'Print summary report for this employee
'Print detailed report for this employee
rsEmployees.MoveNext
Loop
Replace the two commented lines with commands to print the two reports. Depending on whether your EmpNo is numeric or text, these commands will look like either
docmd.OpenReport "MainReport", acViewNormal, , "EmpNo = " & rsEmployees(0)
or
docmd.OpenReport "MainReport", acViewNormal, , "EmpNo = '" & rsEmployees(0) & "'"
Hope this helps.
Related
I have been looking at YouTube for a month learning MS Access. I've created a MS Access report that displays all required info from three tables for 45 distinct systems in my inventory. I want to create a combobox so that the report is only generated for a specific system instead of all 45 as it is doing now. The data bases are joined by the data field called Acronym. I can create a form with a combobox with the acronym's displaying and can select the acronym in the combobox. I cannot figure out how to tie that specific acronym back to generate only the report for that acronym. The report is called RptSystemProfile.
The DoCmd.OpenReport has an optional WhereCondition parameter. you can do something like
DoCmd.OpenReport "RptSystemProfile", acViewPreview, _
WhereCondition := "SystemID=" & cboSystem.Value
This assumes that the system is identified by a column called SystemID (adapt it to reflect the real name). This column must be selected in the query the report is based on. It also assumes this column is a Long
If the column is a string then write
DoCmd.OpenReport "RptSystemProfile", acViewPreview, _
WhereCondition := "SystemID='" & cboSystem.Value & "'"
The also assumes that this Id is the BoundColumn column of the Access ComboBox.
You can have a ComboBox display a text but be bound to an id. The row source of the ComboBox would be a query similar to
SELECT SystemId, SystemName FROM tblSystem ORDER BY SystemName
Then set BoundColumn to 1 and ColumnWidths to 0cm. This hides the first column and displays only the text.
The Value property of the ComboBox then reflects the Id of the selected system.
I have a report (ReportX) that I wish to open from two different forms (FormA and FormB) in my database. I wish to do this because FormA and FormB address different aspects of my data, even if they ultimately get to the same output. ReportX is based on data from QueryX.
The problem I have is that QueryX would ideally filter the data based on the current RecordID in the current form. But I don't know how to accomplish this. I'd like to design QueryX so that the criteria for RecordID is essentially CurrentForm!RecordID, but research suggests that I cannot do this. Must I make separate but otherwise identical queries and reports for each form? Or is there a way to use VBA to define the query criteria when I click on the OpenReportX command button?
I already tried using the WHERE condition in the OpenReport command:
DoCmd.OpenReport "ReportX", acViewPreview, ,"RecordID = " & RecordID
but that did not display the results I wished. I need the report header to display/print for each RecordID and the page count in the page footer to reflect only the current/total pages of the RecordID in question. (In other words, if record 1 is one page, record 2 is two pages and record 3 is three pages, then ReportX, when displaying the first page of record 2, should say "Page 1 of 2" and not "Page 2 of 6.") So being able to display and print a single record properly using record filters would also solve my problem.
Which is the least cumbersome/most possible solution?
You should be able to accomplish this using the WHERE condition argument when you open a report:
DoCmd.OpenReport "rptName", acViewPreview, ,"RecordID = " & Me!RecordID
In the case where a I need more control over a Report's recordsource than what the Where condition argument can do for me, I will set the Reports RecordSource to be blank (after designing the report). Next I write code create the correct SQL statement in the Open Report button's Click event, followed by code to open the report and pass in the SQL as an opening argument for the report.
Private Sub cmdOpenReport_Click()
Dim sSQL as string
sSQL = "SELECT * FROM tblWhatever WHERE RecordID = " & Me!RecordID
DoCmd.OpenReport "rptReportName", acViewPreview, , , ,sSQL
End Sub
Then in the report's Open event I write code to set the recordsource:
Private Sub Report_Open(Cancel As Integer)
If IsNull(Me.OpenArgs) = False Then
Me.RecordSource = Me.OpenArgs
End If
End Sub
If neither of those accomplish what you want then you have an issue of a different sort. It's a little difficult for me to understand why you need All Records to show up in the header but only one record in the detail area. And how you expect to accomplish this. You might be best off trying to write a query first that gives you the exact results that your looking for so you know that it can be done.
As a side note, I actually use very few saved queries in my designs. It's not that there's anything wrong with using them, as the option is there for your convenience. I frequently use raw SQL on both forms and reports and set the RecordSource to the SQL on the Form or Reports Open or Load events.
Yes you can point to form data items in a query, and subsequently use that query in a report. The forms need to be open before the report runs. As far as having a header for each record, that is controlled in the settings of the report and how it displays the data.
In the Field, or Critera you can use the format:
[Forms]![frm_Process_Candidates]![QuestionTemplate]
Where frm_Process_Candidates would be the name assigned to your form, and QuestionTemplate is either the name of a control on your form, or a field from the data source of your form.
If you have a sub-form, there will be another [Form] call in the middle there.
[Forms]![frm_Dropdown_Admin]![frm_Dropdown_Admin_Detail].[Form]![text22]
Access should figure it out from there.
I m using sql 2008. I have one matrix on the report. Data will be as follow
Maths English Science
Gender 5 3 4
Male 1 2 2
Female 4 1 2
Count shows the number of students passed in respective subjects.Data is grouped by gender When user click on count it will be redirect to sub report. Now i want to pass Students Ids to sub report to show that students only. I have tried Join, Split but those functions can be used with parameters only. Not with Fields. Basically i want to pass string of comma separated students ids to sub report.
I have searched on Google but not finding any solution. So awaiting for solution.
I've done this recently by setting a click action in a tablix control. Essentially, I went to the Text Box Properties I went to Action and then set the action as Go to URL. I've then put an expression in for the following (which you can modify to your needs depending on the destination report name and parameters):
=IIf(
Parameters!p_hide_links.Value="y",
Nothing,
"javascript: void( window.open('http://' + window.location.host + '/ReportServer/Pages/ReportViewer.aspx?/Property+Management/" & replace(Parameters!i_this_report.Value, " ", "+") &
"&p_from_date=" & Parameters!p_from_date.Value &
"&p_to_date=" & Parameters!p_to_date.Value &
"&p_lease_exec=" & Fields!submitted_by.Value &
"&p_building_state=" & Parameters!p_building_state.Value &
"&p_division_id=" & Parameters!p_division_id.Value &
"&p_building_id=" & Parameters!p_building_id.Value &
"&p_view_type=d" &
"') );"
)
This might be the answer you are looking for:
Right Click on any text box select TextBox Properties and do as in below jpg.
Now select the detail report from the drop down [create new if its not there]
pass the parameters whichever you wanted to and this will be like input parameter to this sub report and using any details dataset you can show on the report view.
Let me know if you face any problems in that.
Here's what I've done:
I created a Parameter Query in which one of the crtiterias is Between [Start Date] and [End Date]. I then put that Parameter Query along with other bound fields and created a subform. So far, no problems and it works great.
But I'm having issues when it comes to printing or trying to convert the form into a PDF. As soon as I ask it to print, for example, the pop-ups from the parameter query will pop up asking me the dates again and even after I enter them in (again), it keeps asking me multiple times and cancels the print job.
How do I keep the query from essentially running when I'm trying to print what's on the screen? The same thing happens if I'm trying to create a PDF.
In my not so humble opinion, parameters are handled badly in MS Access.
I think having to enter the values in the query whenever it is run (unless it is a one off experimental query) is just wrong headed. It would be so much easier to automate reports like that if you could just pass the parameters.
Typically, I create a report without the parameters in the where clause of the query, and then pass in your own where condition which gets added on Remou's answer here
You could also alter the query in the report before you call it, but that's pretty hackey.
-- Edit --
I see the confusion. I interpreted what you were doing as a report (not a form).
What's likely happening is you that when it tries to render/format the print job, it's having to make multiple calls to form's record source. And that why it keeps asking you for that data.
From what I understand in your question, you have a query that looks like this:
select foo
from bar
where
yaddah_date between [Start Date] and [End Date]
And then you've used that query as the record source for a form that you are trying to latter print as a PDF. First of all you should probably create a report that is an analogue of the form. And then open the report for printing with a filter on it:
DoCmd.OpenReport "myReport", , , , _
"yaddah_date between " & txtStartDate & _
" and " & txtEndDate
(the last part is basically the filter/where clause that report will apply to the results of the query that's generating its data).
If you MUST print the form, you can do something similar
DoCmd.OpenForm "foo", acNormal, , _
"yaddah_date between " & txtStartDate & _
" and " & txtEndDate
Or you can set the filter property of the form/subform.
What I want to do is very simple, but I'm totally new to VBA. I want to open a report and filter it by page number, so that I could open, say, only page 2. I already have a variable for how many pages it is. I just need to know what to put in the filter argument of the DoCmd.OpenReport function.
The overall goal is to export each page as a separate PDF. If I can do the above, I can do the rest, but if there's something really simple I'm missing, I'm open to suggestions. Thanks.
This is Access 2010 by the way.
To print single pages you can work with the printer object ( http://msdn.microsoft.com/en-us/library/ff837177.aspx ) and the PrintOut command ( http://msdn.microsoft.com/en-us/library/aa220516(v=office.11).aspx ), however, it seems likely that you have a natural break, such as a customer record, and these breaks can be used with the Where argument of OpenReport to easily get separate reports.
EDIT re comments
Very roughly:
sSQL = "SELECT SuitableField FROM Atable ORDER BY Something"
Set rs = CurrentDB.OpenRecordset(sSQL)
Do While Not rs.EOF
DoCmd.OpenReport "TheReport", acViewNormal, , _
"SuitableField='" & rs!SuitableField & "'"
rs.MoveNext
Loop
You may wish to do some work to ensure you are choosing reports with data in them.