Custom tab control

Zak14

Registered User.
Local time
Today, 13:26
Joined
Jun 27, 2014
Messages
166
I thought I'd find this to be a fairly common demand and that I'd find the answer by googling, but to no avail.

I've got buttons (on the header of my form) that I plan to make act as tabs for a single record.
Each button should display more information for the same person
(basically, more fields from a different table, but with the same primary-foreign key).
So, when I click (one of) these buttons, a different form should open and display the record assigned with the same primary key.

Anyone know how I can do it?
Just a simple explanation will do.

Fyi, I don't want to use the default tab control because it's ugly and doesn't go well with my theme or my layout.

Thanks!
 
I can't see how the visual effect is any different from using a tab control but perhaps you could have all the sub forms on the form with Visible property set to No. Use code in the click event of each button to change the Visible property of the appropriate form to Yes. The code would also have to set the Visible property of all the others to No to hide any form which has been made visible.
 
I know what you mean about the tab control it's very useful but not pretty.

I would place a subform/subreport control on the form.

The best way to do this would be to create one of the forms you envisage, then drag it onto your main form. It will insert the subform/subreport control automatically and wire it up to your main form at the same time.

Once you have done this, open your main form in design view, then click on the very edge of the form, the subform on your main form. The property sheet should open and it will say it is a "subform/report". Look for that and you will know you have clicked in the right place.

Change the name of this subform/subreport to something like:- "subFrmWinCustomTab". This is important as otherwise it will be named the same of as the form that created it, which is very confusing if you don't know.

The "subFrmWinCustomTab" control has a property "source object" if you look at this it will have the name of the form that you dragged on.

So now knowing this you can switch other forms into this control which (I term wrongly, but for convenience) as a "subform window", hence the name I gave it "subFrmWinCustomTab"

To do the switching, you would have code under your command buttons something along the lines of:-

Me. subFrmWinCustomTab.SourceObject = "NameOfForm"

You may have to change a couple of other properties of the subform subreport namely the link master fields and the link child fields however this will depend on the tables the forms are based on.
 
Last edited:
BTW... I should mention that instead of having multiple forms you switch in and out, you should also consider keeping the number of forms to a minimum by having code which hides or displays controls according to need.

To hide a control (building on the example in my previous post) you would use code something like this:-

me.subFrmWinCustomTab.Form.TextboxToHidesName.Visible = False ....
 
Your command button code would look something like this;-

Code:
Private Sub Command1_Click()
    Me.subFrmWinCustomTab.SourceObject = "NameOfForm"
    Me.subFrmWinCustomTab.Form.TextboxToHidesName.Visible = False
End Sub

Note that you don't need to use the name of the form, you just use:-

Me.subFrmWinCustomTab.Form.Control
 
Thanks for both of your suggestions. Uncle gizmo, u didn't need to explain in that much detail lol, i know my way around but thanks for that.

I'd rather not have subforms as the tabs, for many reasons; an example is that my "record control" buttons are in the footer; having a subform as the tabs would create complications with this and other things.

Is there no way to, maybe, order a command button to open the form and go to the specific record (with the same primary key)
 
I did it by creating a generic form called subform1 in the detail area of the main form. Then on the command button that you're using as a tab, enter code for the On-click event to something like this;
Private Sub Tabbutton_Click()
Me.Subform1.SourceObject = "frmNextform"
End Sub

where frmNextform is the form that you want to open.
As for opening to the right record, in the form query of frmNextform, set the Criiteria of your FK field to the PK field available in your main form. That way the form will always open to the correct person.
Hope this helps
 
I did it by creating a generic form called subform1 in the detail area of the main form. Then on the command button that you're using as a tab, enter code for the On-click event to something like this;
Private Sub Tabbutton_Click()
Me.Subform1.SourceObject = "frmNextform"
End Sub

where frmNextform is the form that you want to open.
As for opening to the right record, in the form query of frmNextform, set the Criiteria of your FK field to the PK field available in your main form. That way the form will always open to the correct person.
Hope this helps

Lol thanks but that goes in line with what the uncle gizmo and bob said - to create a subform. if i do it this way, i will be faced with more problems and a need for more troubleshooting, because of other factors
 
BTW ....

I do think your title for this thread was a bit misleading "Custom tab control"

Your question now appears to be How to open another form, to a specific record.
 
Last edited:
I agree uncle.
Zak 14, are wanting these tabs/buttons to open this second form on top of your original? as a dialog? non-modal so that you can still see or access your original?
 
Thanks uncle, I've found the solution in one of your links.

I've used this code in the button's on click event
Code:
DoCmd.OpenForm "[Form name]", , , "[ID of 2nd Form] = " & Me.[ID]

UPDATE: Actually, that wasn't what I was looking for. It filtered the 2nd form to the 1 ID. That's already what I have, using a different code.
 
Last edited:
Thanks uncle, I've found the solution in one of your links.

I've used this code in the button's on click event
Code:
DoCmd.OpenForm "[Form name]", , , "[ID of 2nd Form] = " & Me.[ID]

UPDATE: Actually, that wasn't what I was looking for. It filtered the 2nd form to the 1 ID. That's already what I have, using a different code.

It's good etiquette to post your solution for the benefit of others...
 
Last edited:
It's good etiquette to post your solution for the benefit of others...

I did, but "actually, that wasn't what I was looking for. It filtered the 2nd form to the 1 ID. That's already what I have, using a different code."
 

Users who are viewing this thread

Back
Top Bottom