PDA

View Full Version : Working with acTabCtl



jthe
10-25-2009, 11:20 PM
Hi All,
thanks for reading this.
My development environment is Access 2003.
I'm currently developing a dynamic form. All of the controls in this form are generated through VBA.

Here is a walk through of my code

1. Form Load
2. Check to remove all controls

dim count as integer
count = myForm.Controls.count
if count > 0 then
for i = 0 to count-1
DeleteControl myForm, myForm.Controls(i).name
next i
end if

3. then createControls method.

In the createControls method, I created a tab object with this syntax:

Dim tabControl as control
set tabControl = Application.CreateControl("myForm",acTabCtl,acDetail)
with tabControl
.name = "Main_Tab"
end with

4. After this tab, I created couple of text boxes


Form works fine if it is the first time i fire the form up, because initialy, there's nothing in the form thus skipping the for loop.
However, if I reload, it will give me
"The control number you specified is greater than the number of controls." message.
Using the debugger, I found out that when acTabCtl is creating a tab object, it created 2 acPage objects as well, and my step#2 DeleteControl method
does not seem to recognize these 2 pages.
Any idea of why it doesnt recognize it ?

My next question is, how do I add pages on to tab and manipulate the pages through VBA ?

Sorry if it's a bit confusing, I hardly do any work in VBA, so really need your help.

Thanks again.

CreganTur
10-26-2009, 09:28 AM
Welcome to the forum- it's always good to see new members.

Creating objects on a form on the fly with VBA is fraught with difficulty. It is far easier to design your form with objects up front, and then control what is shown to the user using the object's Visible property.

I know this isn't the asnwer you want, but it's the real-world solution I would use.

Also, I noticed that you cross-posted this question over at VBForums. In the future, if you cross post, please let us know and provide a link to the cross post. This lets us see if others have answered your question and what they've attempted. Read this article (http://www.excelguru.ca/node/7) for more information.

HTH:thumb

jthe
10-26-2009, 04:42 PM
Hi Randy,
Thanks for your reply. Yes, I did post it on VBForums as well. I'll make sure next time I cross post I'll let it be known.

Thanks again.



PS. I can't tag my url with url tag, it said i have to have at least 5 post point first. Currently I'm on 1.