Access 2013 - open same tabbed form multiple times

In tabbed view, is it possible to open a form with certain filters, then open it again in another tab, with a different filter?
Rick DangerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
Yes, at OnOpen set the value (the page index) of the tab control:

    Dim PageIndex As Integer

    PageIndex = 1  ' 0 to Count of Pages - 1

    Me!MyTabControl.Value = PageIndex

If you mean "open a subform", then make a copy of this on another page of the tab control. They will work independantly.

Rick DangerAuthor Commented:
No, I don't mean subform. What do I put for "MyTabControl" please?
Gustav BrockCIOCommented:
MyTabControl is the name of your tab control.

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Rick DangerAuthor Commented:
Where do I find that?
Gustav BrockCIOCommented:
Oh, it's tabbed view. Missed that.

Then you will open another instance of the form:

    Dim TheOtherFormInstance As Form

    DoCmd.OpenForm "frmYourForm"

    Set TheOtherFormInstance = New Forms!frmYourForm

Gustav BrockCIOCommented:
Sorry, it takes a little more:
Public Sub SecondForm()
    Dim frm As Form
    Dim frm2 As Form
    Set frm = Forms!frmYourForm
    Set frm2 = New Form_frmYourForm
    frm2.Visible = True
    ' Do stuff with frm2
    ' frm2 will close when you exit the function.
End Sub

Open in new window

Rick DangerAuthor Commented:
Thanks, but where do I run this code from please?
Gustav BrockCIOCommented:
That could be from where you now open the first form. Use a similar function instead.

It will open the first instance, then move on and open the second. One method to keep the second open, is to open it as modal. Then the code stops before the Stop line (which you, of course, will remove, it's for demo only) and waits until the user closes the second instance.

Dale FyeOwner, Developing Solutions LLCCommented:
If the reason for doing this is to compare data with the different filters, then keeping track of which form is open and closing them properly, in the order you want, can be challenging.  You might want to consider simply creating a 2nd form identical to the first, but with a different name.
Rick DangerAuthor Commented:
No, it's just that I have a report, "rpt_list_horses" which is actually a list of horses and if you click on a horse, you get his past form on a different report, "rpt_linked_runners", filtered by horse name. But you may wish to look at another horse by clicking on his name on the same report report, "rpt_linked_runners". So this would open that same report, "rpt_linked_runners", but filtered by the other horse name.

Sorry, in my original question I mentioned forms, but I should have said reports.
Gustav BrockCIOCommented:
I haven't tested, but it should work for reports as well.

Rick DangerAuthor Commented:
I'm still not understanding this method. The first report is the same as the second, and potentially, 3rd, 4th, 5th, etc. So I would link to this code on the Open Event of the report?
Gustav BrockCIOCommented:
Well, as you wish. But you mentioned ".. you may wish to look at another horse by clicking on his name on the same report". If so:

    Set rpt2 = New Report_rptYourReport
    rpt2.Filter = "ID = " & Me!ID.Value & ""
    rpt2.Visible = True
    Stop    ' for demo only

Rick DangerAuthor Commented:
This isn't making a great deal of sense to me. I'm sure it's my fault, not yours. However, I clearly need more explicit answers for me to be able to get where I want to get to. Where do I put this code please?

Also, you mention rpt2, which implies, maybe mistakenly, that you have hard-coded that this opens the 2nd instance of that report. If so, can this solution cope with a 3rd or 4th instance?
Gustav BrockCIOCommented:
This would be the OnClick event of the control where the user does ".. clicking on his name on the same report".

And yes, you can open as many as you wish. However, as soon as the report object vanishes, that report is closed. This means that if you wish to have multiple reports open, you must create something that keeps the object(s) open, for example by adding them to a Collection. This method is described here:

It also explains how to get hold on these by use of the hWnd property as they will be named the same.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rick DangerAuthor Commented:
OK, thanks.

I will need to spend time on this to test it out properly, but you have, at the very least, pointed me in the right direction on this so I am happy to award you the points.

Thanks for your time.
Gustav BrockCIOCommented:
You are welcome!

Dale FyeOwner, Developing Solutions LLCCommented:

I've never tried this with a report before, but see attached.  What I found was that if the report was not already present in the Reports collection, instantiating a new report with

set rpt = New Report_Report1

did not work.  So I created a loop to test whether that report was already in the collection, and it now works.  The down side of this method is that since the default view for the report is ReportView, the 2nd version of the report opens in ReportView rather than PrintPreview. Are you familiar with any way to work around this?

 It also was not extensible to 3rd or 4th reports.  I think you would need to create a Collection and assign these reports to the collection in order to extend it beyond 2 reports.
Dale FyeOwner, Developing Solutions LLCCommented:
Oops, I see Gustav has already addressed most of this, except the issue about the default ReportView rather than PreviewView.
Gustav BrockCIOCommented:
No, I haven't played with it, but your observations seem right.

If you set and save the report with DefaultView set to PrintPreview, both instances will open this way.

I believe the Collection method is the simplest to hold the instances open.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.