I have an access database that basically has a form where you can lookup some of the database entries. User types in part number, I check that it exists and if it does I return a report with all the data organized in a nice easy-to-read way.
The problem is that, say I generate the report. And then go back to the Form to query for a different part, the report doesnt update or a new report isnt generated (even if I click the "View report" button multple times).
I was wondering if there is a way to generate a new report (with the same template, from same form, different parameters) and just be able to have multiple reports of the same template with different parts to compare or just to analyse.
-
You'll have to post the code you're using to open the report. Are you using the Open Report method?Rene– Rene2018-09-07 19:52:08 +00:00Commented Sep 7, 2018 at 19:52
-
I didnt code it myself. I used the "Add button" and the Command button wizard to "Open Report". The report itself links to the formdvd.Void– dvd.Void2018-09-07 19:57:37 +00:00Commented Sep 7, 2018 at 19:57
Add a comment
|
1 Answer
As forms can be used multiple times this should work with reports too. Try:
Dim rtp1 As Report_yourReportsName
Dim rtp2 As Report_yourReportsName
Set rpt1=New Report_yourReportsName
Set rpt2=New Report_yourReportsName
rpt1.visible=True
rpt2.visible=True
Keep in mind to put Report_ in front of reports name, like it is done with Form_.
Code to open up to 25 report with one button (button named CommandOpenReports):
'1) Declare a global variable (in the module header, outside of the subroutine) like this:
'Assume we'll never need more than 25 instances of the
'same report open at once
Dim rpt(1 To 25) As Report
Private Sub CommandOpenReports_Click()
Dim I As Long
'2) set a member of the global array equal to the specific instance, filter according to whatever criteria you'd like, and make the instance visible.
For I = 1 To 25
If rpt(I) Is Nothing Then
Exit For
End If
Next
'open rptPOs in separate windows
Set rpt(I) = New Report_Bericht1
rpt(I).Filter = stLinkCriteria
rpt(I).Visible = True
End Sub
Code stolen from Multiple Instances of a Report
6 Comments
dvd.Void
Hi, Where would I add this code? I'm assuming in the "view report" button on the form? or would that be in the On Load event of the report?
ComputerVersteher
Add it where you want to open a report. This code open 2 instances at once for example. For somplicity add a button for each report you want to open (Button1, Button2, Button3) and use one Dim Line and one Set Line with rptN where N is the number of the button. If you want unlimited reports you can use an array see the link in answer.
dvd.Void
Would something like a counter work? Say Dim rtp(counter) As Report_yourReportName Set rpt(counter)=New Report_yourReportName counter++ Note this would be in Swift, I dont know how to append a counter in VBA
dvd.Void
I'm trying that code you mentioned, however I keep getting an error on the line Set rpt(I) = New Report_ViewData. It says User-defined type not defined. I was looking aruond in the project database tree on the Microsoft Access Class Objects it only lists the Form_ objects. It doesnt list any Report_ objects (I have 3 report templates in the database) I dont know if that has anything to do with this
ComputerVersteher
Does the report
ViewData not contain vba-code? If not add an empty dummy event (e.g Report_Open()) then it should be visinle in project. |