473,385 Members | 1,400 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.

Auto-compute on cells of Datasheet

48
Hello,

I got something interesting which I hope it really exist.

If the title isn't understandable enough, I will explain further.

I have a SubForm in Datasheet view.
I set SubForm's Control Source with a SQL query in order to display a table of data.

Example:



Same as the automation in Excel, I want something to be implemented in Access.
Everytime a data in a single cell is changed (input/edit/delete) at runtime in Value column,
the data in Accumulating column will also change.
I tried setting the Control Source of the Accumulating textbox only and it works for a "single row".

Example:
Control Source =[txtValue]+1

But since it says "Accumulating", I wanna add the current Value data with the previous Accumulating data.

Like the one below:



I don't know yet how to set the Control Source.
This is where I am stuck.

How to get the row source of the previous record?
Or....is there a better way to mimic the automation in Excel?
(just accumulating the data by adding the current value with the previous value...just like in Excel but implemented in SubForm Datasheet view)
Dec 4 '09 #1
2 2143
missinglinq
3,532 Expert 2GB
I wouldn't use the Control Source but rather would do the calculation in the txtValue_AfterUpdate() event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtValue_AfterUpdate()
  2.  Me.txtAccumulating = Nz(Me.txtValue.Value, 0) + Nz(Me.txtAccumulating.Value, 0)
  3. End Sub
Linq ;0)>
Dec 4 '09 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi Keirnus. If what you are looking for is an overal total to be updated each time you add a record or change an existing one this can be done. If you are looking for a running sum that adds the previous row value onto the current one then that is not really practicable in an Access data entry form.

For an overall total, if you were displaying your subform in continuous forms view (not datasheet) you would have the form header and footer available to you. In these you can place an unbound textbox whose control source is set to a statement such as

=sum([price]*[unit cost])

or whatever would really represent what you are actually trying to achieve in your accumulator column. Datasheet view does not show the header or footer, unfortunately, but it is still possible to use an unbound textbox on the main form to accomplish this.

As mentioned, if what you are looking for is some way to carry forward intermediate totals from one row to the next - as can be done in Excel - it is not easily possible to do this in Access (or any other SQL-based database). In Excel it is very simple to refer to the previous row and calculate a running sum, say; SQL onthe other hand has no concept of record position, so such an intermediate running sum is not achieveable in the way you might expect if you are used to Excel.

Be aware also that datasheet or continuous form views only have one set of controls in use for the rows displayed, which means that you can't use unbound controls in such rows and get meaningful results displayed. We have an article on why unbound form control values don't persist which explains more than I can here on the reasons why.

-Stewart
Dec 4 '09 #3

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

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
2
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.