Deleting a Form Tab (Page) with VBA

J

Joe D

A2K3 (latest patches), WinXP Pro

Struggling with code to delete (remove) a tab (page) in a form using VBA. I
have a need to modify tab contents in a form through VBA (caption and subform
sourceobject) then remove tabs (pages) no longer needed at that time. My
modification code works without flaw. However, the code I gathered from VBA
Help and MSDN (same as Help) to remove a tab (page) isn't functioning for me.

Here's my code, based on the Help example:

Public Function RemovePage() As Boolean
Dim frm As Form
Dim tbc As TabControl
DoCmd.OpenForm "Salesman Budgets Dev", acDesign
Set frm = Forms![Salesman Budgets Dev]
Set tbc = frm!Tab36
tbc.Pages.Remove
RemovePage = True
DoCmd.Save
DoCmd.Close
End Function

I had to add opening the form in design mode (not included in the Help
example) because other instructions say it is needed and code fails
immediately without it.

I get an error 13 Type Mismatch on "Set tbc = frm!Tab36". Tab36 is the Name
of the page to be removed.

The Help code also includes a Dim of "pge as Page" but never uses it. I
suspect there may be a glitch in the Help example code, or there is something
I just don't see.

I have tried many variations without success (far too many to list here).
If anyone has experience with this situation and can help me get on the right
track with the code, I would much appreciate it.

TIA

Joe D
 
J

Joe D

Alex: Many thanks. And what a fast response! That got me going in the
right direction - through my blind spot re: the control rather than the tab.
The more I looked at my code, the harder it was for me to see it.

However, the 'tbc.Pages("Tab36").Remove' gave me an error that 'Remove' was
not a legal option here. So I rephrased it to:

tbc.Pages.Remove (35)

This gets the 36th tab (indicated range 0-35) - and it works now.

I will incorporate this with my gereric form with 36 tabs and the
caption/subform sourceobject mod code (that counts the tabs used) to choose
the tabs to remove.

I REALLY appreciate this, Alex. What a big help.

Joe D

Alex Dybenko said:
Hi,

Set tbc = frm!Tab36 - instead of page you have to use Tab control name
and
tbc.Pages("Tab36").Remove - to remove page Tab36

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com



Joe D said:
A2K3 (latest patches), WinXP Pro

Struggling with code to delete (remove) a tab (page) in a form using VBA.
I
have a need to modify tab contents in a form through VBA (caption and
subform
sourceobject) then remove tabs (pages) no longer needed at that time. My
modification code works without flaw. However, the code I gathered from
VBA
Help and MSDN (same as Help) to remove a tab (page) isn't functioning for
me.

Here's my code, based on the Help example:

Public Function RemovePage() As Boolean
Dim frm As Form
Dim tbc As TabControl
DoCmd.OpenForm "Salesman Budgets Dev", acDesign
Set frm = Forms![Salesman Budgets Dev]
Set tbc = frm!Tab36
tbc.Pages.Remove
RemovePage = True
DoCmd.Save
DoCmd.Close
End Function

I had to add opening the form in design mode (not included in the Help
example) because other instructions say it is needed and code fails
immediately without it.

I get an error 13 Type Mismatch on "Set tbc = frm!Tab36". Tab36 is the
Name
of the page to be removed.

The Help code also includes a Dim of "pge as Page" but never uses it. I
suspect there may be a glitch in the Help example code, or there is
something
I just don't see.

I have tried many variations without success (far too many to list here).
If anyone has experience with this situation and can help me get on the
right
track with the code, I would much appreciate it.

TIA

Joe D
 
J

John Spencer

Instead of removing the page, why not just set its visible property to false?
That will hide the tab page and you don't need to switch to design view.

Also, if you ever make the database an MDE or use it in Runtime mode, I think
your code to remove the page will fail. Hiding or showing it using the page's
visible property will work in both those cases.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Joe said:
Alex: Many thanks. And what a fast response! That got me going in the
right direction - through my blind spot re: the control rather than the tab.
The more I looked at my code, the harder it was for me to see it.

However, the 'tbc.Pages("Tab36").Remove' gave me an error that 'Remove' was
not a legal option here. So I rephrased it to:

tbc.Pages.Remove (35)

This gets the 36th tab (indicated range 0-35) - and it works now.

I will incorporate this with my gereric form with 36 tabs and the
caption/subform sourceobject mod code (that counts the tabs used) to choose
the tabs to remove.

I REALLY appreciate this, Alex. What a big help.

Joe D

Alex Dybenko said:
Hi,

Set tbc = frm!Tab36 - instead of page you have to use Tab control name
and
tbc.Pages("Tab36").Remove - to remove page Tab36

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com



Joe D said:
A2K3 (latest patches), WinXP Pro

Struggling with code to delete (remove) a tab (page) in a form using VBA.
I
have a need to modify tab contents in a form through VBA (caption and
subform
sourceobject) then remove tabs (pages) no longer needed at that time. My
modification code works without flaw. However, the code I gathered from
VBA
Help and MSDN (same as Help) to remove a tab (page) isn't functioning for
me.

Here's my code, based on the Help example:

Public Function RemovePage() As Boolean
Dim frm As Form
Dim tbc As TabControl
DoCmd.OpenForm "Salesman Budgets Dev", acDesign
Set frm = Forms![Salesman Budgets Dev]
Set tbc = frm!Tab36
tbc.Pages.Remove
RemovePage = True
DoCmd.Save
DoCmd.Close
End Function

I had to add opening the form in design mode (not included in the Help
example) because other instructions say it is needed and code fails
immediately without it.

I get an error 13 Type Mismatch on "Set tbc = frm!Tab36". Tab36 is the
Name
of the page to be removed.

The Help code also includes a Dim of "pge as Page" but never uses it. I
suspect there may be a glitch in the Help example code, or there is
something
I just don't see.

I have tried many variations without success (far too many to list here).
If anyone has experience with this situation and can help me get on the
right
track with the code, I would much appreciate it.

TIA

Joe D
 
J

Joe D

Great idea, John! I'll try that.

Incidentally, while the remove code worked to remove the tabs, when I coded
a close/save for the form at the end of the function, Access crashed - no
error message, just the window asking if I wanted to send a message to
Microsoft together with a backup save window - and the changes were not
saved. This also occurred when I removed the close/save and tried to save or
just close the form (visible in design mode) after the code ran. Any combo
of save, close, manual or code, caused the same problem.

Any ideas? Meanwhile, I'll try the visible approach.

Thanks for your great input.

Joe D

John Spencer said:
Instead of removing the page, why not just set its visible property to false?
That will hide the tab page and you don't need to switch to design view.

Also, if you ever make the database an MDE or use it in Runtime mode, I think
your code to remove the page will fail. Hiding or showing it using the page's
visible property will work in both those cases.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Joe said:
Alex: Many thanks. And what a fast response! That got me going in the
right direction - through my blind spot re: the control rather than the tab.
The more I looked at my code, the harder it was for me to see it.

However, the 'tbc.Pages("Tab36").Remove' gave me an error that 'Remove' was
not a legal option here. So I rephrased it to:

tbc.Pages.Remove (35)

This gets the 36th tab (indicated range 0-35) - and it works now.

I will incorporate this with my gereric form with 36 tabs and the
caption/subform sourceobject mod code (that counts the tabs used) to choose
the tabs to remove.

I REALLY appreciate this, Alex. What a big help.

Joe D

Alex Dybenko said:
Hi,

Set tbc = frm!Tab36 - instead of page you have to use Tab control name
and
tbc.Pages("Tab36").Remove - to remove page Tab36

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com



A2K3 (latest patches), WinXP Pro

Struggling with code to delete (remove) a tab (page) in a form using VBA.
I
have a need to modify tab contents in a form through VBA (caption and
subform
sourceobject) then remove tabs (pages) no longer needed at that time. My
modification code works without flaw. However, the code I gathered from
VBA
Help and MSDN (same as Help) to remove a tab (page) isn't functioning for
me.

Here's my code, based on the Help example:

Public Function RemovePage() As Boolean
Dim frm As Form
Dim tbc As TabControl
DoCmd.OpenForm "Salesman Budgets Dev", acDesign
Set frm = Forms![Salesman Budgets Dev]
Set tbc = frm!Tab36
tbc.Pages.Remove
RemovePage = True
DoCmd.Save
DoCmd.Close
End Function

I had to add opening the form in design mode (not included in the Help
example) because other instructions say it is needed and code fails
immediately without it.

I get an error 13 Type Mismatch on "Set tbc = frm!Tab36". Tab36 is the
Name
of the page to be removed.

The Help code also includes a Dim of "pge as Page" but never uses it. I
suspect there may be a glitch in the Help example code, or there is
something
I just don't see.

I have tried many variations without success (far too many to list here).
If anyone has experience with this situation and can help me get on the
right
track with the code, I would much appreciate it.

TIA

Joe D
 
J

Joe D

John: The 'visible' approach worked perfectly. Thanks for your valuable help.

Joe D

John Spencer said:
Instead of removing the page, why not just set its visible property to false?
That will hide the tab page and you don't need to switch to design view.

Also, if you ever make the database an MDE or use it in Runtime mode, I think
your code to remove the page will fail. Hiding or showing it using the page's
visible property will work in both those cases.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Joe said:
Alex: Many thanks. And what a fast response! That got me going in the
right direction - through my blind spot re: the control rather than the tab.
The more I looked at my code, the harder it was for me to see it.

However, the 'tbc.Pages("Tab36").Remove' gave me an error that 'Remove' was
not a legal option here. So I rephrased it to:

tbc.Pages.Remove (35)

This gets the 36th tab (indicated range 0-35) - and it works now.

I will incorporate this with my gereric form with 36 tabs and the
caption/subform sourceobject mod code (that counts the tabs used) to choose
the tabs to remove.

I REALLY appreciate this, Alex. What a big help.

Joe D

Alex Dybenko said:
Hi,

Set tbc = frm!Tab36 - instead of page you have to use Tab control name
and
tbc.Pages("Tab36").Remove - to remove page Tab36

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com



A2K3 (latest patches), WinXP Pro

Struggling with code to delete (remove) a tab (page) in a form using VBA.
I
have a need to modify tab contents in a form through VBA (caption and
subform
sourceobject) then remove tabs (pages) no longer needed at that time. My
modification code works without flaw. However, the code I gathered from
VBA
Help and MSDN (same as Help) to remove a tab (page) isn't functioning for
me.

Here's my code, based on the Help example:

Public Function RemovePage() As Boolean
Dim frm As Form
Dim tbc As TabControl
DoCmd.OpenForm "Salesman Budgets Dev", acDesign
Set frm = Forms![Salesman Budgets Dev]
Set tbc = frm!Tab36
tbc.Pages.Remove
RemovePage = True
DoCmd.Save
DoCmd.Close
End Function

I had to add opening the form in design mode (not included in the Help
example) because other instructions say it is needed and code fails
immediately without it.

I get an error 13 Type Mismatch on "Set tbc = frm!Tab36". Tab36 is the
Name
of the page to be removed.

The Help code also includes a Dim of "pge as Page" but never uses it. I
suspect there may be a glitch in the Help example code, or there is
something
I just don't see.

I have tried many variations without success (far too many to list here).
If anyone has experience with this situation and can help me get on the
right
track with the code, I would much appreciate it.

TIA

Joe D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top