Free Newsletters:
DatabaseJournal  
DBANews
Database Journal
Search Database Journal:
 
HOME News MS SQL Oracle DB2 Access MySQL PostgreSQL PHP SQL Etc Scripts Links Discussion
internet.com

» HOME
» NEWS
» FEATURES
» SERIES
MS SQL
Oracle
MS Access
MySQL
DB2
» RESOURCES
Products
Scripts
Links
» DISCUSSION
» TECH JOBS

Marketplace Partners
Be a Marketplace Partner




internet.commerce
Be a Commerce Partner
Promotional Golf
Remote Online Backup
Corporate Awards
Shop Online
KVM over IP
Dental Insurance
Calling Cards
Auto Insurance Quote
Compare Prices
GPS Devices
KVM Switch over IP
Promotional Gifts
Disney World Tickets
Baby Photo Contest




MySpace Joins eBay, Yahoo in Open Profile Push

News Corp. Unit Under Fire for Ties to Hacker

Are Non-PC Devices Hurting 'Net Innovation?

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Linked Data Planet Conference & Expo

CA ERwin® Data Modeler Proven database design and modeling. Efficiently analyze, design and deploy effective database solutions. Whitepaper: Manage SQL Server Deployments
Try it free: CA ERwin® Data Modeler


Guide to Oracle 11g and Database Migration
Oracle Database 11g includes more features for self-management and automation, which makes it easier for customers to cost-effectively manage their data. Download this Internet.com eBook for an overview of some of the new features in 11g and for an overview of the issues you need to consider as you prepare for a database migration. »
Innovate Faster with Oracle Database 11g
Read this in-depth analysis of 56 customers, which shows significant differences between the value software vendors Oracle and SAP deliver to midsize companies. »
Oracle Business Intelligence Standard Edition One
Find out how Newport Beach, CA-based Mobilitie is shaking up the telecom industry by leveraging technology to provide an entirely different financial model for deploying, upgrading, and owning wireless and wireline network assets. »
Business Intelligence and Enterprise Performance Management: Trends for Emerging Businesses
Quickly implementing an ERP software solution can be of tremendous benefit; however, companies often struggle to balance the benefits of reducing implementation time and cost with the risks of an accelerated deployment. Read this white paper to learn about easy-to-follow best practices for achieving a successful accelerated implementation. »
Making the Case for Oracle Database on Windows
Users benefit as vendors reduce enterprise complexity and deliver integration. »

Production Manager (hands on)
Aquent
US-MA-Cambridge

Justtechjobs.com Post A Job | Post A Resume
MS Access
April 20, 2006
MSAccess: Load Subforms Dynamically
By Danny Lesandrini

I frequently see comments and questions on the newsgroups about how to improve performance with Microsoft Access applications. The knee-jerk reaction is to blame the platform, but in most cases, that's not the problem. There are many things a developer can do to squeeze an incredible amount of power and performance out of an Access database. The first, and foremost, is to avoid loading data until you need it. One way to do this is through the smart implementation of subforms.

Subforms are one of the great features of Microsoft Access. If you have ever tried to replicate the Form/Subform paradigm of Access in Visual Basic, you will appreciate how simple the process really is.

1.      Create the master form

2.      Create the child form

3.      Drag child form and drop on master form

4.      Set the Link Master Field and Link Child Field properties

5.      Get a cup of coffee; you're done!

The down side is that it is too simple to add subforms. Once a developer gets started creating subforms, they often don't know when to quit. Before long, they have a dozen subforms pointing to a dozen related tables referencing thousands of related records. Is it any wonder performance suffers?

So, how do you get around this performance hit? Simple; don't load any data until the user actually asks to see it. That is what this month's article is all about and as usual, the code is available in the download file.

The image below tells the whole story. My form has a tab control with four pages, one for each of the tables referenced. The first page has fields of the master form embedded in it while the other three pages will reference its corresponding subform. However, as you can see from the design-view image of the form below, there aren't any subforms embedded on these tab-pages. There is one unbound Subform object floating around in the upper right-hand corner where it appears out of place.  Through code, it is dynamically resized, moved and loaded with the correct subform, depending on which page is selected. Let's take a look at the code that manipulates this simple control.

Dynamically Load Subform on Page Change

The code for this process is very, very simple. If there is a trick, it is knowing which event receives the code. When I was preparing the code for this article, I instinctively selected the Click() event instead of the Change() event. Needless to say, it did not behave as I had intended. Once I corrected that issue, things proceeded pretty smoothly. Check out the code, and keep in mind this is all the code in the entire application.

   Private Sub tabPublisher_Change()
      On Error Resume Next
 
      Dim strSubformName As String
      
      ' Based on the page selected, set the Subform Name variable
      Select Case Me.tabPublisher
         Case 0: strSubformName = ""
         Case 1: strSubformName = "sfrmAdditionalInfo"
         Case 2: strSubformName = "sfrmEmployeeInfo"
         Case 3: strSubformName = "sfrmPublisherTitles"
         Case Else: strSubformName = ""
      End Select
   
      ' If a subform exists, then set the properties, otherwise
      ' just hide the generic subform object
      If strSubformName = "" Then
         Me.objSubform.Visible = False
      Else
         Me.objSubform.SourceObject = strSubformName
         Me.objSubform.LinkMasterFields = "pub_id"
         Me.objSubform.LinkChildFields = "pub_id"
         
         Me.objSubform.Top = Me.lblAnchor.Top
         Me.objSubform.Left = Me.lblAnchor.Left
         Me.objSubform.Width = 0.95 * Me.tabPublisher.Width
         Me.objSubform.Height = 0.75 * Me.tabPublisher.Height
         
         Me.objSubform.Visible = True
      End If
   
   End Sub

Notice the tight code method used in the Select Case statement. This syntax makes sense in our application since each case performs a simple variable assignment and the code is clean and easily readable. I could have combined the Select statement with the code in the If branch, but that would have resulted in repetition of the subform property assignments. However, if your subforms need to be sized or placed differently, that is exactly what you would do.

Of special interest is the pair of properties that set the LinkMasterFields and LinkChildFields. All of my subforms share the same common field, pub_id. In most cases, the Primary Key of the master form is likely going to be the one on which the subforms are linked, but there may be times the subform properties are different. In that case, you may set the link properties dynamically.

Final Thoughts

By implementing this paradigm, the number of table connections was cut from guaranteed four references to either one when page p00 is selected, or two when one of the other pages is active. While this performance gain is not likely noticeable with this little demo application, it is very appreciable where there are tens of thousands of records and ten or more subforms.

This trick alone was enough to completely solve performance issues for one of my clients.  After months of "why is this application so slow?" complaints, and hours of pouring over server settings, the basic issue described above of loading data only when it's requested solved my problems and made me a hero.

» See All Articles by Columnist Danny J. Lesandrini

Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

MS Access Archives

Data Sheet: IBM Information Server Blade
Webcast: Five Virtualization Trends to Watch. Produced for HP, Citrix, and Intel.
What's The Future Of IT? Find Out By Reading "IT in 2018" Now. Free Registration Required.
Download: SQL Backup & DBA Best Practices eBook
HP eBook: Using Business Service Management (BSM) to Manage Your Business Applications


Latest Forum Threads
MS Access Forum
Topic By Replies Updated
Export a report into excel Irina_5220 4 May 9th, 01:50 PM
Table Property Question barlowr70 0 May 6th, 10:51 AM
Compile MS Access Database samson 1 May 1st, 03:28 AM
How to connect MS-Access with c++ rockys111 0 April 30th, 01:36 AM







JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES