Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem previewing multiple Report Instances 1

Status
Not open for further replies.

RichWilson

Technical User
May 30, 2011
4
US
Help Please. I am trying to display previews of multiple instances of a Report named "rpt_parts_sheet".

My code below seems like it's going to work; it starts to pull up the previews but then it gives an error something like, there was a problem retrieving the printer information...

I just want it to pull up the previews so they can be viewed on the screen and selectively printed if the user wants.

DoCmds with acviewpreview does exactly what I want, but I can not seem to open multiple instances with that method.

If I need to let it retrieve printer information, is there anyway to just let it use the user default system printer?

Thanks for any help anyone can give.

My code as follows...

Private Sub Parts_Sheet_Click()

Dim agroup(2) As Report_rpt_parts_sheet
Dim z As Long


For z = 0 To 1
Set agroup(z) = New Report_rpt_parts_sheet
Next z

With agroup(0)
.Caption = "Requested Group"
.Filter = "gm_group_no = '" & Combo18 & "'"
.FilterOn = True
.Visible = True
End With


With agroup(1)
.Caption = "First Related Group"
.Filter = "gm_group_no = '" & Combo18 & "'"
.FilterOn = True
.Visible = True
End With

End Sub
 
Hi Rich,

If memory serves me right, you can only have one copy of the report open at a time.

To have multiple copies open just make several copies of the original report and then open the copies.

Hope This Helps,
Hap...

Access Developer [pc] Access based Accounting Solutions - with free source code
Access Consultants forum
 
Sure you can have multiple report instances open. I am not sure of some of your code. Looks like you are trying to mix and array and a collection. The error however may have nothing to do with your code.

'Need a public collection to hold instances. Has to be modular in scope

public col as collection

public sub someProcedure()
dim rpt as report_rpt_parts_sheet
dim i as integer

for i = 0 to 1
set rpt = New report_rpt_parts_sheet
with rpt
.someproperty = ..
.someproperty2 = ..
.visible = true
end with
col.add rpt,"Some Name" & I
next i
end sub

now you can refer to a specific report through the collection.

col("Some Name1").someproperty
 
Thank you so much. I will try to get what you've suggested to work for me. I will report back in a couple of days.

I'm just getting into collections, classes, modules and the like. I'm still a little green. I've spent a lot of time looking for this answer. Thanks!
 
actually I think your code is almost correct as I look at it, except you dimension your array within the procedure.

Dim agroup(2) As Report_rpt_parts_sheet

instead you should do this outside the procedure

Public agroup(2) As Report_rpt_parts_sheet

If you do this inside the procedure, the procedure runs the reports open and then the procedure finishes and the array goes out of scope. So basically the reports open, but then immediately close and disappear.

It looked strange to me at first because I never use arrays to hold objects, always collection. Its easier to work with.
 
Thanks MajP.

Thanks to you I finally got it to do as I wanted. However, I couldn't quite get it to work like your suggested code, but some of the things you said helped me to understand some of the other code examples that I had previously pulled off the net. Someone else with a little more programming experience than me probably could have taken your code and run with it though.

I'm going to explain what I did, first for you to comment on if you will please to let me know if what I have done is considered acceptable practice or not, and two, possibly to help someone else do what I was trying to do.

Let me explain my purpose. I have a master table of some items or what we call groups; some of these groups are inter-connected or related with other groups. When you pull up one group you will also need the information for the related groups also. Therefore, in my master table for each group (record), I have set aside 12 fields to hold the group numbers for any related groups. Most will have nowhere near 12 related groups but 12 should cover any possiblity that I can foresee. For simplicity I only showed two earlier. Since they are all groups that can utilize the same report, this is why I wanted to have muliple instances of the same report. I can modify the one report when necessary and update all the reports at one time and
therefore all the reports will also be consistant.


My code and explainations are as follows:
=================================================================
Option Compare Database

Dim col As New VBA.Collection ' Added this to the top, above
' the procedures, to Dim the
' collection.
_________________________________________________________________

Private Sub Parts_Sheet_Click()

Dim rpt As Report_rpt_parts_sheet
Dim stSubfld As Variant
Dim stFilter As String
Dim stCaption As String
Dim I As Integer

' I must capture the current requested group and the
' 12 related group for use in the procedure. I will use an array.
' The first one stSubfld(0) which is what's held in Combo18 is
' the group that the user selected. The remaining are the 12
' fields containing the related groups for the selected group.

stSubfld = Array(Combo18, sub_group_1, sub_group_2, sub_group_3, sub_group_4, sub_group_5, sub_group_6, sub_group_7, sub_group_8, sub_group_9, sub_group_10, sub_group_11, sub_group_12)

' Now I will cycle through the array. I am stepping through the
' array backwards. Since the first report pulled up will be on
' the bottom when all is complete. I want the selected main
' group on top when all is done and the rest in order as shown.

For I = 12 To 0 Step -1

' Now, I only want to open a report if there is a subgroup listed
' in any of the sub group fields, so I will use an If Statement.

If stSubfld(I) <> "" Then
Set rpt = New Report_rpt_parts_sheet ' Note the 'NEW' keyword
rpt.Filter = "gm_group_no = '" & stSubfld(I) & "'"
rpt.FilterOn = True
rpt.Visible = True
' Using an If statement to determine the captions on
' each of the reports...
If I = 0 Then
stCaption = stSubfld(I) & " - The Group You Requested"
Else
stCaption = stSubfld(I) & " - #" & I & " Group Related to " & stSubfld(I)
End If
rpt.Caption = stCaption 'set the caption

col.Add rpt, "rpt" & I ' Adds each report to the collection.
' I understand that I can use this to refer back to any of
' the reports later if needed. "rpt0", "rpt1", etc.

End If
DoEvents ' Lets the system have some processer time if needed.
' I don't think my database is large enough to make
' a 'DoEvents' necessary, but perhaps larger databases
' may.

Next I ' Process the next report for the next iten in array.

' I do not, but if you wish the following command cascades
' all open forms and reports. Note: It does not change their
' displayed order.

DoCmd.DoMenuItem 0, 4, 1 ' Cascades all open Forms and reports

End Sub
=================================================================

For basic simplicity, I have foregone any error handling within my procedure. Not-to-mention, I am not adept enough with them to suggest any anyway.

Thanks All, I'm so happy now.
Richard
 
Well thought it was working perfectly, but it still needs a way to clear the collection before the next run-through.
 
you can write a simple procedure to delete all items in your collection, basically loop the collection and delete each item.

or here is a simple way

change this

Dim col As New VBA.Collection

To

private col as vba.collection

The difference is that I took out the New (Dim to private does not make a difference, but private is more exact) When you put New the collection is immediately instantiated (built). Without it you are just reserving some memory (like a be prepared message).

then somewhere inside your procedure you instantiate
set col as New collection (Here the collection is built)

So every time you call the procedure it creates a new instance. It is a single instance just recreated (not multiple instances).

Now as far as the Subgroups. Not sure if you want to fix that, but obviously you have some database normalization problems. Any time you see a database with repeating fields of the same data where you might not use them all, it is bad design. Your subgroups is a one to many or more likely a many to many relationship.

So likely you should have a junction table

tblGroups_RelatedGroups
groupID_fk
relatedGroupID_fk

ex
1 2
1 3
1 5
2 1
2 13
2 14

So group 1 is related to 2,3,5
group 2 is related to 1,13,14

If there is no parent child dependency, but equally related then you need to show both relations. If 1 is related to 2, then you should also have the record showing 2 is related to 1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top