Full Version: Tab Control - Add New Tabs - Query Based
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
fullyunknown
Ok... I was wondering if this was at all possible..

I Have a form that has a Tab COntrol on it. I had the idea of listing the days of a month that have reports due based on query.

For example, out of a month days 2, 5,8 only have reports due. So when you open the form it runs the query to see what days have a form due. Once it gets it go through and add tabs for each day. This is what I got :
CODE
Dim MyDB As DAO.Database
Dim qdef As DAO.QueryDef
x = 1
Set Db = CurrentDb
Set rs = Db.OpenRecordset("SELECT D_List.Report_Due FROM D_List GROUP BY D_List.Report_Due")
If rs.EOF = False Then
With rs
    .MoveFirst
    Do While Not .EOF

        TabCtl1.Pages.Add
        TabCtl1.Pages(x).Caption = rs!report_due
     x = x + 1
    .MoveNext
    Loop
    End With
End If
rs.Close


Well of course ran into the rpoblem that when i open the form it tells me that you can only add pages to a tab control while in design view. is there anyway around this?
pere_de_chipstick
Hi fullyunknown

No I don't believe you can add tabs except in design mode.

It is however possible to hide or unhide tabs, so if you create all the tabs you need on the design, then set each tab's visible property to 'No' then your code can then make the required tabs property visible as needed.

A maximum of 31 tabs would be needed if all the days in the month were required, but presumably you would never need reports on all 31 days and can limit the number of tabs required.

Personally I would use a method where there was a single sub form (or / on a tab), the report days would be selected in a combo box and the selection would display the appropriate data in the subform / tab

HTH
fullyunknown
I orginally had the the form doing as you stated. However, I was trying to be creative since i was expanding upon this idea, because when you click on a date my idea was to have it show a sub form with its own tab control on it that list the different reports, which of course was suppose to be generated in the same way. It was a crazy inovated way but i guess access isnt advanced enough to do it :-( ... Thanks for your help.
pere_de_chipstick
yw.gif
fullyunknown
Follow-Up In Case Anyone Else for any odd reason wants to do what I wanted...

1.) The following code will assign your subform to being blank.
2.) It opens the subform, that you will eventually diplay, in design view.
3.) Removes all Tabs except the main tab, which has the default layout for each tab you add.
4.) Looks at a query to find out what reports are going to run on the particular day you choose.
5.) Takes each one of these days and creates a tab for it and names the tab that report.
6.) Saves the the form
7.) Finally, assigns the subform; the form that you just edited and created tabs for

CODE
Me.Child116.SourceObject = ""
DoCmd.OpenForm "frmDate", acDesign, , , acFormEdit, acHidden


y = 1
final_y = Forms.frmDate!TabCtl_Date.Pages.Count
Do While y <> final_y
    Forms.frmDate!TabCtl_Date.Pages.Remove (1)
    y = y + 1
Loop

'''''''Generate the TABS for the specfic date
Dim MyDB As DAO.Database
Dim qdef As DAO.QueryDef
x = 1
Set Db = CurrentDb
Set rs = Db.OpenRecordset("SELECT D_List.Report_Name FROM D_List WHERE (((D_List.Report_Due)='" & page_name & "') AND ((D_List.Report_Deactivated)=0)) GROUP BY D_List.Report_Name")
If rs.EOF = False Then
With rs
    .MoveFirst
    Do While Not .EOF

        Forms.frmDate!TabCtl_Date.Pages.Add
        Forms.frmDate!TabCtl_Date.Pages(x).Caption = rs!report_name
        
     x = x + 1
    .MoveNext
    Loop
    End With
End If
rs.Close

DoCmd.Close acForm, "frmDate", acSaveYes
Me.Child116.SourceObject = "frmDate"
pere_de_chipstick
Hi fullyunknown
Glad you found a solution that meets your needs thumbup.gif,

Just one point though: you will not be able to distribute your app (if you need to) as
mde/accde files as these formats will not allow the form to be opened in design view.

HTH

Good luck with your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.