473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

using previous row's closing column in current row's opening column in Access 2007

ariful alam
185 100+
Hello,

I have a ms access table named transaction. The fields are:
trans_id,
trans_date,
product,
storage,
received,
issued

Now, i want to create a select query that include all the columns mentioned above, plus two more columns named,
Opening_balance and Ending_balance in the query.

Opening_balance should contain previous row's Ending_balance column value

and

Ending_balance should contain current row's (Opening_balance + received - issued).

I like to do it using Expression Builder, not using VBA code. Is there any suggestion for it.


Thanks
Jun 19 '12 #1
2 2894
PGAC
7
Hi ariful alam,



I can think of two ways to get what you want but there is no simple solution that I can think of for what you are asking for.

First Way
=========

If trans_id is an interupted numercial sequence then you could create a query from the trans table and add a calculated field:

trans_id_previous: [trans_id]-1.

Save this query. Create a new query which uses the trans table and the above query you can then link [trans_id] to the [trans_id_previous] field from the query. This way, you have the current record from the table linked to its previous record inthe query. You can then add more calculated fields to get what you want.

To be honest, this is not a particularly nice way of doing it but it does avoid VBA. If there are gaps in the [trans_id] field though then you can forget about doing it this way.

Second Way
==========

Add two new fields to the trans table called [Opening_balance] and [ending_balance] and use VBA code to create either a DAO or ADO recordset which then goes through all records in the table and calculates the opening and ending balances. Ensure records are in the correct order though. This is the better solution and is not affected by gaps in the [trans_id] field.

Good luck.
Jun 23 '12 #2
ariful alam
185 100+
@PGAC, thanks for your reply. Yes, there is trans_id gap as every transaction is based on product and storage group.

When i was failed to get the the opening balance and closing balance using query, i add two field in the named o_balance and c_balance in the table Transaction. And query every corresponding product's and storage's last c_balance to use as new transactions o_balance and o_balance + received - issue = new c_balance.

And Jazak'Allah Khair (Thanks) you.
Jun 26 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Joel | last post by:
Hi! Its probably a stupid question but how can I retreive the column of the current row? Example: This retreive the value in the ID column for the first row. dstForeignKey.Tables(0).Rows(0)("ID")...
1
by: Larry Lard | last post by:
I've got a Windows Forms app talking to an Access db, and I'm experimenting with VS2005's form data binding stuff etc. I've got a dataset, a datagridview bound to a query (let's call it...
49
by: Allen Browne | last post by:
If you are looking for opinon on what's useful in Access 2007, there's a new article at: http://allenbrowne.com/Access2007.html Covers what's good (useful features), what's mixed (good and bad),...
4
by: Peter | last post by:
Access 2007 optionally opens forms as tabs. There is an Access Option that controls this - Access Options Current Database Document Window Options Tabbed Documents. But how, from VBA, can I...
17
by: Neil | last post by:
A client of mine likes some of the new bells and whistles in Access 2007, and is thinking about converting our A03 format MDB to an A07 format file. However, while some of the users have A07, many...
4
by: lupo666 | last post by:
Hi everybody, this time I have three problems driving me nuts :-((( (1) I have a report with 20 or so Yes/No "squares". Is there a way to either hide/show the "square" or change the yes/no...
10
by: Lou O | last post by:
I have been using Access 2007 for a number of months and have successfully deployed ACCDR files on many client machines. The client machines have the "free" Access runtime version installed. I...
0
by: WPW07 | last post by:
Hello Everyone, I stumbled onto something interesting and was wondering if anyone else has experienced it and how they fixed it. I've posted to several forums to no avail. I've got a...
0
by: Sport Girl | last post by:
Hello everybody. Please can somebody give me a hand with this issue: How cam I get the Grand Total by row and by column in a Pivot Table in Access 2007. Regards
8
by: DanicaDear | last post by:
I have something interesting...looking to see if anyone else has came across this. I have a query with parameter and and the query works beautifully every time. However, when I use the wizard...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.