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

Safety Awareness for Hotel Workers

By: Nikunj M Patel | 01/01/2010
hotel workers who do a lot of house keeping work always have to lift heavy objects or be constantly exposed to cleaning chemicals. For instance, the act of changing bed sheets requires the hotel work to bend down, lift the mattress up with both hands, and slip the sheets under the mattress. Mattresses are considered heavy objects, especially if one has to repeat the same movements several times a day. If not careful, this seemingly harmless act can lead to severe back injuries.

Middleman System New Review December 31st

By: Clare Clements | 31/12/2009
Aymen and his team at former Arbitrage Conspiracy have released Middleman System on December 17th, through a Special Webcast ,with Guesr Brian Tracy what is to be the Biggest Launch in the Internet marketing History.

Why Virtual CFOs Have to Be Better, Faster and Smarter

By: Scott A. McPherson, CPA, CFG, CVA | 31/12/2009
There’s no doubt that the realm of the CFO has shifted dramatically. And by some economic and marketplace indicators, dynamic virtual CFOs, especially those who specialize in partnering with small and mid-sized businesses, could become the next generation of chief financial officer professionals. That is, as long as those virtual CFOs stay better, faster and smarter.

ERP Software: Increase the Efficiency of Your Engineering Department

By: S. Daggle | 31/12/2009
Manufacturing companies rely on their engineering department in order to secure a profit. While the sales department initiates leads, the engineering department is in charge of creating products and filling orders which ultimately results in the sale and revenue. This means that the efficiency of your engineering department directly affects...

How Do I Earn Extra Incomes - Extra Incomes With Style

By: Rok Pisek | 31/12/2009
Do you need extra income and are you willing to have it? We are talking about extra income to develop your lifestyle level or even to give a chance to quit your current work and start to work on internet which can make your life easier. Of course there exists many...

What makes a toddler an entrepreneur?

By: Kim Roddy | 31/12/2009
There are numerous fables of people who have risen from to being a downtrodden person to an entrepreneur. These are the people who were once an employee and after conquering a series hardships and adversities of life they attain the position where they generate employment for others and become a source of inspiration for the society and for who strive to be successful

Global Warehouse Management Systems (WMS) Market in Retail Industry

By: Bharat Book Bureau | 31/12/2009
Bharatbook.com added a new report on "Global Warehouse Management Systems (WMS) Market in Retail Industry 2008-2012" into its market report catalogue for reselling.

When Employee Conflict Gets Ugly

By: Imelda Bickham | 31/12/2009
Employee conflict can be healthy when it aims at resolving differences and finding a common ground. Conflict becomes harmful when it aims at winning, and proving that one is right and the other person is wrong.

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

Ms Access Tip: Keeping Up With User Activity

By: Jon Watson | 25/10/2007 | Technology
At times you will find it very handy to know what a user was doing in your application at a specific time. This is especially useful with multi-user database applications for debugging or security reasons. With this tool implemented in your applications you will be able to see what event happened and at what time.

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.27, 4, w3)