Remember Me
forgot your password?

Ms Access Tip – How to Use Variables in the Access Query Design Form

MS Access Tip – How to use variables in the Access query design form.

In this example you are going to learn how to enter or select data in one form and open another form with more data related to the field you just selected by taking advantage of global variables in the query design form. To help achieve this, you will use a global variable entered in the criteria of a field while creating the query in the Access query design form. The result is a powerful user interface function that allows a user to look up more data, or enter more data related to a selected record. Users can use it to look up pricing histories, addresses, inventory locations, really anything where you would have more data about a key field in your database.

You can achieve this by learning to use global variables. These variables can be accessed by any form, query, macro, or other modules while you are in the Access session. Use a module to store these variables in.

There are several simple steps to achieve this functionality.
Create a global variable in a module
Create your data table.
Create the source query for the “look up” or pop up form
Create the pop up form with the source query as the data source
Create the form to enter the selection from and enter the VBA code to the pertinent control events on the form to open the look up form.

1) Create a module with the following few lines of code.

Option Compare Database
Public DFname As String

Public Function GetVFname () As String
GetVFname = VFname
End Function

2) Create a table with the following fields for demonstration sake. ID as an autonumber. Then create Fname, Lname , Street, City, St, Zip, County, Phone as text fields and lastly add DOB as a date field.

Set the form to be a pop up form. While in design mode, make sure the form is selected and then on the “Other” tab turn the Pop Up setting to yes. Save the table naming it Client.

3) Next create a query to use as the data source for your form. Use the Client table as the source and select all the fields from the table field list using the Windows shift select feature and drag them down to the field view portion of the Query by Example form. Now in the ID field, set the Criteria as:
GetVFname ()
Close the query and save it as IDQry

4) Create a form using the query you just created as the data source. So, on the Data tab on the form select IDQry. Just put all the fields on the form for this example. Save it as ClientData.

5) Create a second form and use the client table as the data source. This form is used to demonstrate selecting a record with a double click event and getting the pop up form with more information related to the selected record.

In a real application you may want to access data from other tables/forms in the same way. Pull in the Id, Fname and Lname fields only. Close and save the form as NameLst.
Put the following code on the double click event of the Id field. This will open the “ClientData” form with the selected Client.

Private Sub ID_DblClick(Cancel As Integer)
VFname = Me.ID.Value
DoCmd.OpenForm “ClientData”, acNormal
End Sub

Now to see this example work, simply open the NameLst form and double click on the ID field in any record.

This example was created with Access 2002. There are more than likely many different ways to accomplish the same functionality, but we have found that this general approach is the most scalable to larger applications.

Jon Watson

Jon Watson is the founder of Biomation Systems, Inc. With 26 years experience helping Fortune 500 companies with process improvement he formed BioMation to bring the same expertise to smaller companies that need the same improvements at an affordable price.
You can find more help for MS Access at:
www.biomationsystems.com
www.accessdatabasehelp.com
www.accesshelpebook.com

Rate this Article: 0 / 5 stars - 0 vote(s)
Print Email Re-Publish

Add new Comment



Captcha

  • Latest Management Articles
  • More from Jon Watson

HOW CAN A COMPANY REDUCE COSTLY ABSENTEEISM CAUSED BY SMOKERS?

By: John English | 24/12/2009
Become active in helping smoker-employees to stop smoking permanently. Find a method that is easy to administer, risk-free, rapid, cost-effective and that WORKS! A solution is proposed that will turn smoker-employees into highly motivated team members, while providing very positive publicity for the company and its management. Win-Win.

PANLEGIS - simple, efficient and quick company formations

By: Joakim Gustafsson | 24/12/2009
An experienced company formation agent will take care of all sides of your company registration – from suggesting M&As;to registering with the national registrar of companies.

MLM lead system

By: Ryan | 24/12/2009
An MLM lead system is most important factor in MLM marketing.

Versatility of CMMS Products

By: Ashley Combs | 23/12/2009
Versatility of CMMS products is a highly coveted and appreciated feature for any business. Enterprise Asset Management allows you to get the most out of your plant assets in order to cut overhead and keep business costs low. No matter what CMMS products that a business implements, the tools for cost evaluation and equipment maintenance will benefit any business.

What Makes Revamped Office Furniture Can Become Just The Ticket For All Offices

By: Aleks G | 23/12/2009
In our modern society, there is never-ending conversations in the area the preservation of precious resources.

WordPress can make easy to use Content Management System

By: spinxwebdesign | 23/12/2009
WordPress is very versatile software program which can be used for many purposes. One of the biggest advantages of WordPress is, it is almost free and using it one can easily make a decent website. This article will present an overview on how WordPress can be used as CMS.

Ideal Bookkeepers and Bookkeeping

By: vish ks | 23/12/2009
The chief aim of any individual who sets up a business is to earn substantial income. In order to conduct business in the appropriate way, one needs to have at least some acquaintance with the different operations associated with it. Well, regarding bookkeeping activities, considering the current economic scenario, it would be prudent to hire the services of some professional bookkeeping firm.

Bookkeepers Adopt a Meticulous Approach

By: vish ks | 23/12/2009
All Companies must conduct an accurate analysis of the bookkeeping affairs for the faster growth of the Company. Bookkeeping as such is an assortment of multiple activities. Usually organizations and Companies employ a few accountants and bookkeepers for handling their accounts. But, the very concept of maintaining a huge workforce in the bookkeeping department is not recommended nowadays.

Ms Access Tip – you Have Heard ofs, Now Learn to Use Them

By: Jon Watson | 11/01/2008 | Management
This example demonstrates using an array and SQL statements to create the similar records. It also has a function to replace records if you want to change the amount value and update the data table. The replace function assumes that the description and date are the same and replaces every occurrence of the existing record with the latest amount value. For safekeeping the replace function makes a copy of the data table before executing.

Ms Access Tip – How to Use Variables in the Access Query Design Form

By: Jon Watson | 26/12/2007 | Management
In this example you are going to learn how to enter or select data in one form and open another form with more data related to the field you just selected by taking advantage of global variables in the query design form

Ms Access Tutorial - How to Use Color Coding to Enhance your Applications

By: Jon Watson | 18/12/2007 | Management
Color coding adds value to a form as it easily directs the user's eye to critical data. This is a powerful technique that allows a user to quickly evaluate a pages of data for errors or warning information.

How to Get the Most From your Training Dollar

By: Jon Watson | 12/12/2007 | Management
There are so many people telling you that you can make such a huge return on your investment these days that you just can't believe any of them any longer. I know, I have received so many get rich emails that I should be earning about a billion a day now! How about investing in something that you really believe in. Yourself.

Ms Access Tip: Self Learning Combo Box

By: Jon Watson | 12/11/2007 | Technology
Database data entry can be tedious at times. You can make your databases more user friendly if they have a way to select data to enter rather than typing in the same data over and over. Access provides a form control called a combo box to help with this task but it can lead to trouble.

Access Databasetip: Create a User Defined Search Field for a List Box

By: Jon Watson | 02/11/2007 | Technology
Many times it is necessary to provide your users with an easy way to filter or search for data in large table of information. This tip will show you one quick and easy way to solve the problem by giving the user a field to enter a search string and updating the form with those fields that fit the search pattern. It's quick and easy, so give it a try. Read about how Access was a big success solving a license tracking issue in this article.

Access Database Tip: How to Multiselect in a Listbox

By: Jon Watson | 26/10/2007 | Technology
When you have a list box it is handy to be able to multiselect to perform some action on multiple items in the listbox. Here is a simple set of instructions to get you started. These instructions will create a quick way to multiselect and delete rows from a table.

Submit Your Articles Free: Signup

Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.20, 1, w2)