Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3
This is the forum to discuss the Wrox book Access 2007 VBA Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Armen Stein; ISBN: 9780470047033
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 28th, 2007, 02:13 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating multiple instances programmatically

I refer to th eexample on p. 447, in which textboxes are subclassed. Code shows making a subclass instance for each textbox on the form manually. I.e.,

   set FirstTB.myTextbox = Me.txtFirst 'i.e., the first textbox control
   set LastTB.myTextbox = Me.txtLast

I would like to do this programmatically:

   For each ObjCtl in Form.Controls
       aTB = new clsTextbox
       aTB.myTextbox = ObjCtl
   next

Obviously, this code keeps reassigning to "aTB." What I'd like is:

   i=0
   For each ObjCtl in Form.Controls
       i=i+1
       aTB(i) = new clsTextbox
       aTB(i).myTextbox = ObjCtl
   next

But this is not how VB works, I think. Any help appreciated.

Reply With Quote
  #2 (permalink)  
Old December 28th, 2007, 02:40 AM
Wrox Author
 
Join Date: May 2007
Location: , Washington, .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thank you for your question and for checking out the book!

Access/VBA does not natively support control arrays as does VB6, however, you might be able to simulate it using something like:

Dim aTB() As clsTextbox

Private Sub Form_Load()
    ReDim aTB(Me.Controls.Count)

    Dim i As Integer
    Dim j As Integer
    Dim ctl As Control

    For Each ctl In Me.Controls
        If (TypeOf ctl Is TextBox) Then
            i = i + 1
            Set aTB(i) = New clsTextbox
            Set aTB(i).MyTextbox = ctl
        End If
    Next
End Sub

Hope this helps,

Rob Cooper
Lead Software Design Engineer in Test
Microsoft Access Team

co-author: Access 2007 VBA Programmer's Reference
co-author: Expert Access 2007 Programming

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at microsoft.com/info/cpyright.htm.
Reply With Quote
  #3 (permalink)  
Old December 28th, 2007, 12:51 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Rob. I'll give it a try. Your book is excellent and very helpful!

Reply With Quote
  #4 (permalink)  
Old December 28th, 2007, 02:12 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Rob. It worked!

Reply With Quote
  #5 (permalink)  
Old December 28th, 2007, 02:21 PM
Wrox Author
 
Join Date: May 2007
Location: , Washington, .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're welcome! I'm glad you are enjoying the book.

Rob Cooper
Lead Software Design Engineer in Test
Microsoft Access Team

co-author: Access 2007 VBA Programmer's Reference
co-author: Expert Access 2007 Programming

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at microsoft.com/info/cpyright.htm.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with creating Multiple instances of Form i vb_programmer Pro VB 6 1 June 29th, 2006 10:29 PM
Multiple browser instances Dilip Nagle Classic ASP Basics 1 September 29th, 2005 10:33 PM
Replace multiple instances of a String interrupt Javascript How-To 2 June 14th, 2005 06:48 AM
multiple instances of same spreadsheet opening Jingels Excel VBA 1 January 31st, 2005 02:03 AM
One form in multiple instances. Sink Access VBA 0 June 7th, 2004 04:25 AM



All times are GMT -4. The time now is 10:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.