Using this code I am trying to use my code to delete Tabs form a main "Tab", but I am missing the correct method somehow
`Private Sub DeleteAlltabs(frm As Object)
Dim tabCtrl As TabControl
Set tabCtrl = frm.Controls("Tab")
If Not tabCtrl Is Nothing Then
For i = tabCtrl.Pages.count - 1 To 0 Step -1
tabCtrl.Pages(i).Remove
Next i
End If
End Sub`
I even tried it with a while wend, and a slightly different code, but something seemingly so simple is not working:
If Not tabCtrl Is Nothing Then
While tabCtrl.Pages.count > 0
tabCtrl.Pages.Remove tabCtrl.Pages(tabCtrl.Pages.count - 1)
Wend
End If
my components are:
- Visual Basic for Applications
- Microsoft Access 16.0 Object Library
- OLE Automation
- Microsoft Office 16.0 Access Database engine Object Library
I tried both codes, and wanted it to delete the tabs, but it gave me a syntax error on both accords.
As Bilel explained,
tabCtrl.Pages(i)refers to onePagein the tab control'sPagescollection and aPageobject does not have aRemovemethod.So you must use
Pages.Removeinstead. If you want to target a specific page based on its index, you can do this:Or if you omit the index, the last page will be removed:
I think the second version simplifies the task. Here is the code I tested:
Another issue is that "You can remove a Page object from the Pages collection of a tab control only when the form is in Design view." (see Pages.Remove method)
So I opened the form in Design View before calling the modified subroutine: