Remember Me
forgot your password?

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

In this example I show how to create a table of similar data that may only have a date in difference. For example, you want to evaluate how your cash will flow and you have a table of expenditures. You know that you have regular payments for payroll, loans, taxes etc. that you want to put into your transaction data table without having to key in every record when maybe only the date is different. An example would be, you have twelve tax payments, all the same but in different months.

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.

This example requires a form, a module and a three tables to support it.

Create the following Module and name it.

Make sure you set the references to include the MS DAO 3.6 Library. Cut and paste the following code.

Option Compare Database

Option Explicit

Public misql As String, Midb As Database, MiRec As DAO.Recordset, MiRec2 As DAO.Recordset

Public Function GetMiSQL()

Set Midb = CurrentDb()

Set MiRec = Midb.OpenRecordset(misql, dbOpenDynaset)

End Function

Public Function GetMiSQL2()

Set Midb = CurrentDb()

Set MiRec2 = Midb.OpenRecordset(misql, dbOpenDynaset)

End Function

Public Function PutMiSQL()

Dim Midb As Database ', MiRec As DAO.Recordset

Set Midb = CurrentDb()

Midb.Execute misql

End Function

Table 1. Cash

Amount currency

Cdate date/time

Desc text

Once you have created this table close and save it as Cash. Make a copy of it and name it CashBac. It will be used to make a copy of your data before you do a replace.

Table 2. Repeats

Item text

Amount currency

Occr number

DOM number

Set both of the number items properties Integer. Close and save the table as Repeats.

Create Form “Transactions”

Use table “Repeats” as the datasource

Put a Form header and footer on the form

Place all the fields from the table on the form.

Place all the field labels in the form header above their respective field placed in a single row in the detail section of the form. Format the form as a Continuous Form.

Place two buttons in the form footer and name them BT1 and BT2.

Change the caption for BT1 to Create and for BT2 to Replace.

Place the following code in the form. Open the form in design view, then click view code from the menu tool bar. This opens the VBA editor. You can just cut and paste from this file to avoid typing.

Cut Here.

‘************************

Public Function DoRept()

Dim ItemVal(12, 4) As Variant

Dim Recnt As Integer, RDate As Date, xtimes As Integer

misql = "SELECT Repeats.Item, Repeats.Amount, Repeats.Occr, repeats.dom FROM Repeats;"

GetMiSQL

MiRec.MoveLast

Recnt = MiRec.RecordCount

MiRec.MoveFirst

For X = 1 To Recnt

ItemVal(X, 1) = MiRec(0)

ItemVal(X, 2) = MiRec(1)

ItemVal(X, 3) = MiRec(2)

ItemVal(X, 4) = MiRec(3)

xtimes = MiRec(2)

'Debug.Print ItemVal(x, 1) & " " & ItemVal(x, 2) & " " & ItemVal(x, 3) & " " & ItemVal(x, 4)

For z = 1 To xtimes

RDate = z & "/" & ItemVal(X, 4) & "/08"

misql = "INSERT INTO Cash ( [Desc], Amount, [Cdate]) SELECT '" & ItemVal(X, 1) & "' AS x1, " & ItemVal(X, 2) & " AS x2, #" & RDate & "# AS x3;"

PutMiSQL

'Debug.Print misql

Next

MiRec.MoveNext

Next

getout:

MiRec.Close

End Function

'*********************

Private Sub BT1_Click()

DoRept

End Sub

'***********************

Public Function DoReplace()

Dim ItemVal(12, 4) As Variant

Dim Recnt As Integer, RDate As Date, xtimes As Integer

misql = "SELECT Repeats.Item, Repeats.Amount, Repeats.Occr, repeats.dom FROM Repeats;"

GetMiSQL

misql = " DELETE CashBac.* FROM CashBac;"

PutMiSQL

misql = "INSERT INTO CashBac SELECT cash.* FROM cash;"

PutMiSQL

MiRec.MoveLast

Recnt = MiRec.RecordCount

MiRec.MoveFirst

For X = 1 To Recnt

ItemVal(X, 1) = MiRec(0)

ItemVal(X, 2) = MiRec(1)

ItemVal(X, 3) = MiRec(2)

ItemVal(X, 4) = MiRec(3)

xtimes = MiRec(2)

'Debug.Print ItemVal(x, 1) & " " & ItemVal(x, 2) & " " & ItemVal(x, 3) & " " & ItemVal(x, 4)

For z = 1 To xtimes

‘change the 08 value in the next line to the current year or set a value on the form and change it with a ‘variable.

RDate = z & "/" & ItemVal(X, 4) & "/08"

misql = "UPDATE Cash SET Cash.Amount =" & ItemVal(X, 2) & " WHERE Cash.Desc= '" & ItemVal(X, 1) & "' AND Cash.Cdate= #" & RDate & "#;"

PutMiSQL

‘Debug.Print misql

Next

MiRec.MoveNext

Next

MiRec.Close

End Function

'***********************

Private Sub BT2_Click()

DoReplace

End Sub

'***********************

Cut Here.

This should do it. As always, there are many different ways to accomplish something similar to this. This works for me and saves a lot of time when I want to run several what if’s with my cash flow analysis. This example was created with Access 2002 and runs as listed on my system. This is a free example and I can’t support it or make changes with out compensation so please don’t ask.

This example and many others can be found on our website at www.biomationsystems.com

All of the examples found there are accompanied by a functioning Access database file.

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

4 Sure-Fire Signs You Need Additional Personnel

By: Cookie Tuminello | 08/12/2009
When too little time equals too much stress, it’s time to look at hiring additional personnel in your business.

System Misconceptions

By: Tim Bryce | 08/12/2009
What it is not.

EBilling Benefits

By: Shelley Veazie | 08/12/2009
The internet has given us the freedom to conduct business almost exclusively in "the cloud." We are now communicating almost solely via online interactions and yet much of our billing is still done via fax machines and snail mail. With the advances in security and analysis technology, any company that...

Cisco Call Manager and Cisco Unified Communications

By: Shelley Veazie | 08/12/2009
The internet has become an integral part of our everyday lives, both at work at home. However, there are applications that still need some work. The internet's ever-growing and ever-changing technologies seem to be making our lives easier, but there is still some room for improvement. Unified Communications Enters the World's...

Call Accounting Solutions: What Are Your Options and How do They Work?

By: Shelley Veazie | 08/12/2009
Integrated Call Accounting and Management Solutions The most recent news in call accounting is the addition of telemanagement services. Call accounting data or call detail records are often times just presented as raw data and are not nearly as effective as when they are analyzed and evaluated by a telemanagement service....

Change the Look of Your Office With Used Cubicles

By: Sdfurniture | 08/12/2009
If the current economy has you down, but you know that your office needs a face lift to keep employee morale up, you should consider the possibility of investing in used cubicles to spruce up your office and provide for a streamlined and easy working environment for your employees.

Workflow Management: The Key to World-class Customer Service

By: Manny de Sousa | 08/12/2009
There are a lot of processes that are involved in business operations, and one of them is workflow management. This basically refers to the passing of data—may it be in image, document, or whatever else—from one person to another. It may also be passed on through the use of a machine.

Building Website using WordPress Magazine Themes

By: spinxwebdesign | 08/12/2009
You need to update content regularly to keep your audience coming back for more information because nobody wants to look at a poorly designed website. Many people have started magazine using the WordPress magazine themes for their needs. This has increased the popularity of WordPress and it has become one the best content management systems.

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.

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
Article Categories




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.48, 7, w2)