Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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.

  #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.
  #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!

  #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!

  #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.


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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.