473,395 Members | 1,974 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,395 software developers and data experts.

How to compare data between 2 consecutive records in a table

9
I have a database that records results from devices that uses an algorthmic code as its meter. I capture from and to readings. I would like to compare readings between 2 consecutive records to see if there is a gap n the readings. Therefore, I would like to compare the "TO" reading in one entry to the "FROM" reading in another for gaps.
Sep 16 '10 #1
5 3372
Oralloy
988 Expert 512MB
Well, do a select of your records, sorted on timestamp, and walk them to inspect for differences.

Expand|Select|Wrap|Line Numbers
  1. Pseudo code:
  2.  
  3. rs = SELECT * FROM [table] ORDER BY [timestamp]
  4.  
  5. value1 = rs("value1")
  6. value2 = rs("value2")
  7. etc...
  8.  
  9. next rs
  10.  
  11. for each remaining rs
  12.   new1 = rs("value1")
  13.   new2 = rs("value2")
  14.  
  15.   display (new1 - value1) and (new2 - value2)
  16.  
  17.   value1 = new1
  18.   value2 = new2
  19.  
  20.   next rs
  21. end
  22.  
  23. done
Cheers!
Sep 16 '10 #2
kimmer
9
Thanks for the code. It makes sense. I have programmed in the past and am new to Access. I do not understand where this code would be inserted. I have done macros on events for forms, but not on reports. How or where would I insert this code?
Sep 20 '10 #3
Oralloy
988 Expert 512MB
kimmer,

It's pseudo code, not real access code.

I assume that you are hanging your differences code off of a form button or other event handler.

If you need help just getting off the ground, I'm probably not the best coach. Still, I'll help you as best I can.

Luck!
Sep 20 '10 #4
kimmer
9
Orally,
Just got back to this. I am performing this code in a report not a form. What event handler would you suggest I use to connect this code to?
Sep 27 '10 #5
Oralloy
988 Expert 512MB
Kimmer,

Is the report simply being run, and the differences (i.e. missing record) shown for all records, except the first?

As I said earlier, I may not be the best coach. I really am unfamiliar with reporting in Access.

I tried with the difference code in Detail_Paint(), like so, but I'm not sure that is the best way to go about it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Paint()
  2.   On Err GoTo ohNo
  3.  
  4.   Dim status1 As Variant
  5.   status1 = Me![Status]
  6.  
  7.   If IsNull(status0) Then
  8.     Text2 = "s0: Null" & ASCII.CRLF & _
  9.             "same"
  10.   ElseIf (status0 = status1) Then
  11.     Text2 = "same: " & status0
  12.   Else
  13.     Text2 = "diff: " & status0 & " / " & status1
  14.     status0 = status1
  15.   End If
  16.  
  17.   Exit Sub
  18.  
  19. ohNo:
  20.   MsgBox "Error here:" & ASCII.CRLF & Err.Description
  21. End Sub
  22.  
  23. Private Sub Report_Open(Cancel As Integer)
  24.   status0 = Null
  25. End Sub
  26.  
The problem is that my initialization code in Report_Open(...) is in the wrong place. I'm not sure where to put it.
Sep 27 '10 #6

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

Similar topics

2
by: Antoni | last post by:
Hello, I wondered if anyone could offer some guidance, I trying to write a php script to connect to a database, and display the records in a table. I found the code here in a php4 text, and...
9
by: paul | last post by:
Hiya everyone, I have two tables in SQL 2000. I would like to append the contents of TableA to TableB. Table A has around 1.1 Million Records. Table B has around 1 Million Reocords. ...
3
by: Bill W. | last post by:
I almost hate to ask this, it's so trivial. I am writing some code to read a text file and place certain records (based on key words in the file) into a form and table. I have the code written...
2
by: indigo | last post by:
hi.. can someone suggest the best way to move data from one table to another. i'm trying to do this mainly due to my own limitations with regard to access. i have a form which has various cells...
8
by: LimaCharlie | last post by:
Hi, Question pls. I have an MS SQL local package where it exports data from SQL table to Excel file. My question is, how can I erase all the records in my excel file before i export the new data...
12
by: Randy | last post by:
Hi, Trying to pass along a table row delete to the datasource, but I'm crashing. Here is the code: Private Sub btnDeleteIngr_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
3
by: ramakanth05 | last post by:
Hi, I have a problem pulling data from a table using the parameter as table name. I have three tables tbl1, tbl2, tbl3 and I want all the records of the table based on the parameter given. ...
6
by: mservice | last post by:
Hi there, newbie to Access, I would normally use cursors in SQL Plus to do this type of thing, however I have been tasked with modifying an access 2000 application and am stuck on the VB code/query...
2
by: NazishKanwal | last post by:
Hi all I have a table in which I save a record each time when a user checks in and checks out the office through a time in/ time out device(this device takes thumb impression of user, thus ...
2
by: frankj | last post by:
I have a database in which survey data is entered twice (by coder A & B). Coder A's Form is linked to a table storing their data. Coder B's form is linked to a table storing their data. In every...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.