Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| 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 May 5th, 2009, 08:16 PM
Registered User
 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Post Chapter 19: Creating the Recordset

This code comes from Chapt 19, p 686 in the Creating the Recordset section and the sub PopulateFields():

Code:
If Not g_rsFormSource.BOF And Not g_rsFormSource.EOF Then
              Me.txtCompanyName.SetFocus
                      Me!txtCompanyName.Text = g_rsFormSource.Fields("CompanyName")
                       Me.txtContactName.SetFocus
                       Me!txtContactName.Text = g_rsFormSource.Fields("ContactName")
                       Me.txtContactTitle.SetFocus
                       Me!txtContactTitle.Text = g_rsFormSource.Fields("ContactTitle")
                       Me.txtCustomerID.SetFocus
                       Me!txtCustomerID.Text = g_rsFormSource.Fields("CustomerID")
                       Me.txtFax.SetFocus
                       Me!txtFax.Text = g_rsFormSource.Fields("Fax")
                       Me.txtPhone.SetFocus
                       Me!txtPhone.Text = g_rsFormSource.Fields("Phone")
    Else
                       ' Throw an error
    End If
That seemed pretty bulky to me and not very flexible, so I played around for a while and came up this this:

Code:
Dim ctlC As Control
Dim strC As String
    If Not g_rsFormSource.BOF And Not g_rsFormSource.EOF Then
            ' For each control.
    For Each ctlC In Me.Controls
                    If ctlC.ControlType = acTextBox Then
                                 ' Get the name of the current control
                                 strC = ctlC.Name
                                 ctlC.Value = Nz(g_rsFormSource.Fields(strC), "")
                     End If
             Next ctlC
    End If
It saves you the trouble of setting the focus on each control and allows you to populate controls that are not enabled. It also means that you don't have to modify the VBA every time you modify the form.

It seems to work pretty well, but if anybody has any reasons why I shouldn't take this approach, I'd like to hear it. I will add in error processing later.

Thanks,
Victor

Last edited by NuovoData; May 5th, 2009 at 09:19 PM.. Reason: Changed some of the var names in my code to match that of the book.
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
Chapter 19 johanyu BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 3 November 12th, 2007 10:50 AM
Chapter 19 XML kistaw BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 0 November 12th, 2007 03:56 AM
Scripts for chapter 19 ValF BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 3 March 10th, 2006 12:03 AM
Chapter 19 Exercise CharlieChan BOOK: Beginning Visual C++ 6 0 June 19th, 2005 05:15 PM
Chapter 19 johanyu BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 October 10th, 2004 11:30 PM



All times are GMT -4. The time now is 02:04 AM.


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