Got a TabControl. Add a page. Now create a new control and glue it to the page

P

Phlip

Access forms coding:

Ogle this sample code from threads of yore:

Public Sub NewTab()
Dim newpage As Page
Dim ctlTab As Control
Dim frmTab As Form

DoCmd.OpenForm "frmTab", acDesign
Set frmTab = Forms("frmTab")
Set ctlTab = frmTab.Controls("TabControl")

Debug.Print "before pages.count = " & ctlTab.Pages.Count
Set newpage = ctlTab.Pages.Add

Debug.Print "after pages.count = " & ctlTab.Pages.Count
DoCmd.Save acForm, "frmTab"
DoCmd.OpenForm "frmTab", acNormal

Set newpage = Nothing
Set ctlTab = Nothing
Set frmTab = Nothing
End Sub

Notice the programmer did nothing with 'newpage'.

I want to do something with it! How can I push a new control into it?
newpage.Controls.Add does not exist.
 
M

Marshall Barton

Phlip said:
Access forms coding:

Ogle this sample code from threads of yore:

Public Sub NewTab()
Dim newpage As Page
Dim ctlTab As Control
Dim frmTab As Form

DoCmd.OpenForm "frmTab", acDesign
Set frmTab = Forms("frmTab")
Set ctlTab = frmTab.Controls("TabControl")

Debug.Print "before pages.count = " & ctlTab.Pages.Count
Set newpage = ctlTab.Pages.Add

Debug.Print "after pages.count = " & ctlTab.Pages.Count
DoCmd.Save acForm, "frmTab"
DoCmd.OpenForm "frmTab", acNormal

Set newpage = Nothing
Set ctlTab = Nothing
Set frmTab = Nothing
End Sub

Notice the programmer did nothing with 'newpage'.

I want to do something with it! How can I push a new control into it?
newpage.Controls.Add does not exist.


You would refer to the page in the CreateControl function.

If you are thinking of doing this at run time (instead of as
a little helper procedure at design time), forget this idea
and precreate the controls and manipulate their Visible
property at run time.
 
G

Guest

you missed the line of code where the programmer did use newpage:
Set newpage = ctlTab.Pages.Add

that will add a new tab
 
B

Brendan Reynolds

From a recent thread ...

Newsgroups: microsoft.public.access.modulescoding
Subject: Re: Creating controls on a page object
Date: Sun, 17 Jul 2005

Public Sub TestSub4()

Dim frm As Form
Dim tbc As TabControl
Dim pge As Page
Dim txt As TextBox

DoCmd.OpenForm "Form2", acDesign
Set frm = Forms("Form2")
Set tbc = frm.Controls("TabCtl0")
Set pge = tbc.Pages.Add()
pge.Name = "MyNewTabPage"
pge.Caption = "My New Tab Page"
CreateControl frm.Name, acTextBox, _
acDetail, pge.Name, "=Now()", _
pge.Left + 50, pge.Top + 50, 2000, 250

DoCmd.Close acForm, "Form2", acSaveYes

End Sub
 
P

Phlip

Brendan Reynolds wrote:

Thanks, but...
DoCmd.OpenForm "Form2", acDesign

....sorry, dude. I have to move the goalpost. I need the feature in running
mode, not design mode. (Like all the other TabControls on the planet...)

I suspect, per other threads, that I can't do that, and I am expected to use
a function like yours, at design time, to blast in a thousand tabs, make
them all invisible, and visible the populated ones at runtime.

What I actually need is a "filmstrip" control, like the one in the Windows
Explorer. So what I will eventually do is put 10 pages into a virtual
TabControl, and repopulate the labels as the users navigate back and forth.
CreateControl frm.Name, acTextBox, _
acDetail, pge.Name, "=Now()", _
pge.Left + 50, pge.Top + 50, 2000, 250

CreateControl was the missing function! Now I remember using it 8 years ago.
Friggin' Alzheimers...
 
B

Brendan Reynolds

You're right - you can't do that.

Controls can only be created in design view. Also, there's a limit of 754
controls or sections added over the lifetime of the form, which you'd
eventually hit if you created controls each time the form was opened.

You'll need to create the maximum number of controls you may ever need at
design time, and toggle their visibility at run time.

I've read that if you open a form in design view, create controls, switch to
form view, and then when closing the form do not save the new controls, they
do not count toward the 754 limit. But I have not tried this myself. The
form would still have to be opened in design view first, which means that it
will not work in an MDE, or using a runtime installation, or where the user
does not have change design permission on the form.
 

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