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
Memory Upgrades
Compare Prices
Memory
Promotional Products
Home Improvement
Online Education
Imprinted Gifts
Holiday Gift Ideas
Promotional Golf
Desktop Computers
Best Price
Televisions
Condos For Sale
Promotional Pens




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


Solaris 8 Migration Assistant
Rapidly move your Solaris 8 application environments to new systems running Solaris 10 with the Solaris 8 Migration Assistant. Reduce migration risk while taking advantage of increased performance, reliability and security of the latest SPARC hardware platforms and Solaris 10 OS. »

 
Sun Eco Innovation: Good for Business, Good for the Environment
A complete solution to help you optimize and refresh your datacenter while properly recycling equipment and eliminating eWaste, including money-saving promotions to lower hardware acquisition costs. »

 
Sun Eco Innovation: Power Calculators
Power consumption has increasingly become a priority in customer's minds when purchasing new systems or storage. Sun's Power Calculators provide data on power consumption of Sun products allowing IT managers to better plan the power requirements in the datacenter to achieve better energy and cost savings. »

 
Optimize the Web Tier: Consolidate to Get More Performance in Less Space and Lower Power Consumption
Expansion in the Web tier is generally accomplished by adding more servers whenever extra capacity is needed. As the pool of servers grows larger, however, the complexity of the environment can grow exponentially. »

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

Justtechjobs.com Post A Job | Post A Resume
MS Access
May 25, 2006
Implement User Preferences in MS Access
By Danny Lesandrini

A couple of years ago, one of my clients asked me to change the background color for their four primary forms because one user with poor eyesight needed greater color contrast. While that user loved the new schema, others hated it and before long, I was toggling colors like a madman, trying to find a happy medium. That is, until I decided to give the users the ability to set their own colors, and along the way, added a couple of other preference options of various degrees of usefulness. It occurred to me that this process might be of interest to DBJ readers. Here is how it works.

The image below shows three different forms, each with a different color schema applied, just to give you an idea of havoc that may be reaped by allowing users to pick their own colors. While the artsy part of this feature is fun, the other preferences can really enhance the user experience. For example, here are some of the things I have applied to user preferences:

  • Allow user to select which form opens at startup
  • Remember and open the last record visited
  • Identify specific Fax-Printer to use with reports
  • Indicate data source for table linking
  • Set flag for running in 'development' mode

Of course, you will need to code the logic behind each of these suggestions, but the process of setting and saving user options remains relatively consistent. The code, including the preferences form, which you may import into your project, is available in the download file.

User Preference Option Form

The first part of this process involves using the built-in Access functions for saving values to and retrieving values from the registry. They are very simple to use, following the syntax shown below, as described in the Office help file:


    SaveSetting appname, section, key, setting
    GetSetting(appname, section, key [, default])

These calls to the registry may be used anywhere in the application and in my experience, do not produce a performance hit. The code behind the Preferences form has the highest concentration of such calls, so that snippet is shown below. Note that I use a constant, cAppName, for the appname argument. This assures that my registry settings are consistent. The other arguments, section and key, can and probably should vary, depending on what sorts of preferences you are saving, but it is entirely up to you how you organize your registry entries.

Private Sub Form_Load()
   On Error Resume Next
      
   ' Lookup values from the REGISTRY using the GetSetting() method
   '
   Me.chkRememberID = GetSetting(cAppName, "Options", "Remember ID", False)
   Me.fraStartupForm = GetSetting(cAppName, "Options", "Startup Form", 1)
   Me.txtMinorColor = GetSetting(cAppName, "Options", "Minor BgColor", -2147483633)
   Me.boxMinorColor.BackColor = Nz(Me.txtMinorColor, -2147483633)
   Me.txtMajorColor = GetSetting(cAppName, "Options", "Major BgColor", -2147483633)
   Me.boxMajorColor.BackColor = Nz(Me.txtMajorColor, -2147483633)
   
   ' Apply form color formatting to current form
   '
   Me.FormHeader.BackColor = Me.txtMinorColor
   Me.FormFooter.BackColor = Me.txtMinorColor
   Me.fraStartupForm.BackColor = Me.txtMinorColor
   Me.lblTitle.BackColor = Me.txtMajorColor
   Me.lblStartupForm.BackColor = Me.txtMajorColor
   Me.Detail.BackColor = Me.txtMajorColor
   
End Sub

In the demo app, I have opted to update the registry each time a value changes, in the AfterUpdate() event. Once saved to the registry, it is immediately available to the application.

' Each time a control value changes, update the REGISTRY
' using the SaveSetting() method.
Private Sub txtMajorColor_AfterUpdate()
   On Error Resume Next
   SaveSetting cAppName, "Options", "Major BgColor", Nz(Me.txtMajorColor, -2147483633)
   Me.boxMajorColor.BackColor = Nz(Me.txtMajorColor, -2147483633)
End Sub
Private Sub txtMinorColor_AfterUpdate()
   On Error Resume Next
   SaveSetting cAppName, "Options", "Minor BgColor", Nz(Me.txtMinorColor, -2147483633)
   Me.boxMinorColor.BackColor = Nz(Me.txtMinorColor, -2147483633)
End Sub

Calling the StartUp Form Preference

The above code sample for frmPreferences Form_Load() event demonstrates how a color selection may be applied to the BackColor property of form sections and/or individual controls. This same logic needs to be propagated to all other forms that you wish to affect by the user-selected colors.

A similar process is used to determine which form opens at startup. It is customary in my applications to load a splash screen, which handles application open processes, so the demo database includes a form named frmSplash. When this form opens, it performs the following test:

   intStartupForm = GetSetting(cAppName, "Options", "Startup Form", 3)
   
   Select Case intStartupForm
      Case 1
         ' no form ... close splash
         DoCmd.Close acForm, Me.Name
      Case 2
         DoCmd.OpenForm "frmPublishers"
         DoCmd.Close acForm, Me.Name
      Case 3
         DoCmd.OpenForm "frmPreferences"
         DoCmd.Close acForm, Me.Name
      Case 4
         DoCmd.OpenForm "frmTipOfDay"
         DoCmd.Close acForm, Me.Name
      Case 5
         ' do nothing.  Splash form requested.
   End Select

The registry contains a key for the application named "Startup Form" which holds an integer value between 1 and 5. If it is missing, then the default value, 3 for frmPreferences, is substituted. A simple case statement evaluates this integer variable and opens the appropriate form.

Preferences Many Uses

It should not be difficult to see how this process could be extended to handle the many and varied needs of your application. Even if you have no interest in propagating infinite color schemes, there are undoubtedly some preferences that your users would appreciate being able to preserve.

As mentioned in the introduction, I have one implementation where users can set the option to return to the last visited record. Imagine how convenient it would be for users to open their app on Monday morning and immediately be navigated to the record they left off with last Friday afternoon.

I have one user who wants me to program all their report buttons to send the results directly to the printer without having to preview it. That's nice for them, but a pain to debug problems. Finally, I ended up adding a user preference option that sets a value for sending reports to the printer or preview window. My client gets to print them and with the flip of an option, I preview them. It has saved me hours of dinking around with code, changing DoCmd.OpenReport options.

The same idea could be applied to any number of development verses production options. Any of the following could be set at startup based on user preferences saved to the machine's registry.

  • Set option to Break On All Errors
  • Turn off developer's custom error logging
  • Point to development database instead of production
  • Bypass startup checks and/or security options

I have an Access developer friend who is going to chide me because he has told me many times how I can use Compiler Constants to do the same thing. However, it isn't quite the same, because I have to remember to toggle the constants on and off each time I roll it from production to development and back. With registry entries, the application stays the same and the behavior follows the machine, not the mdb file. I don't have to worry that my users will observe "developer" type options, because their registry is not set to do so.

Yes, it takes a little bit of code to propagate the effects of user-saved preferences, but the benefits they provide to your applications are limited only by your imagination.

» 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
HP eBook: Using Business Service Management (BSM) to Manage Your Business Applications
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers. Sponsored by HP, Citrix, and Intel.
IT in 2018: Download Free eBook By The Author Of "Does IT Matter?" Simple Registration Is Required.
Download: Solaris 8 Migration Assistant. Run Solaris 8 apps on the latest SPARC systems and Solaris 10.


Latest Forum Threads
MS Access Forum
Topic By Replies Updated
Export a report into excel Irina_5220 2 May 9th, 08:48 AM
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