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

What are the benefits of .AbsolutePosition property?

294 256MB
I came across the .AbsolutePosition property on MS Office Dev Center website and was curious as to its' importance.

I've been active on Bytes primarily as far as VBA/Access forums are concerned and often I see people post Do While loops, yet they don't contain .AbsolutePosition. There is always the same starting point

Expand|Select|Wrap|Line Numbers
  1. If .BOF Or .EOF Else
But I never see .AbsolutePosition.

That begs the question - when is a good time to use it, and what are its' uses?

If I'm being too vague - please let me know! Thanks
Feb 18 '14 #1
11 2661
ADezii
8,834 Expert 8TB
I use it primarily to track the progress of a Loop as a percentage of Records processed, as in:
Expand|Select|Wrap|Line Numbers
  1. 'It is Zero based, so
  2. (rst.AbsolutePosition/rst.RecordCount)
P.S. - Code obviously omitted.
Feb 18 '14 #2
NeoPa
32,556 Expert Mod 16PB
It's something that gives you the position of the current record within the recordset.

NB. This is not the relative position of the record in the table, as that is meaningless. It is also not 100% reliable, as other members have noticed. As ADezii has said, it can be useful for determining progress through a recordset.
Feb 18 '14 #3
ADezii
8,834 Expert 8TB
@mcupito:
Here is another context for which .AbsolutePosition can be used. I forgot to mention that I also use it to pluck a Random Record from a Recordset, namely generating a Random Number between 1 and .RecordCount then setting .AbsolutePosition to it.
Expand|Select|Wrap|Line Numbers
  1. Dim rst As ADODB.Recordset
  2.  
  3. Set rst = New ADODB.Recordset
  4. rst.Open "tblCustomers", CurrentProject.Connection, adOpenKeyset
  5.  
  6. Debug.Print rst.Fields(0).Value
  7.  
  8. 'Move approximately halfway into Recordset
  9. rst.AbsolutePosition = 0.5 * rst.RecordCount
  10. Debug.Print rst.Fields(0).Value
  11.  
  12. 'Move to the 35th row
  13. rst.AbsolutePosition = 35
  14. Debug.Print rst.Fields(0).Value
  15.  
  16. rst.Close
  17. Set rst = Nothing
Feb 18 '14 #4
mcupito
294 256MB
Thanks for the examples, ADezii. Thanks for the reply, NeoPa.

That being said - are there foreseeable problems in this code :

Expand|Select|Wrap|Line Numbers
  1.     DoCmd.Hourglass True
  2.     DoCmd.SetWarnings False
  3.         DoCmd.OpenQuery "CheckConfirmVestUpdateQry"
  4.         DoCmd.OpenQuery "CheckConfirmPytUpdateQry"
  5.     DoCmd.Hourglass False
  6.     DoCmd.SetWarnings True
  7.  
  8.     With Recordset
  9.         If .AbsolutePosition = .RecordCount - 1 Then
  10.         'you are on the last record
  11.             DoCmd.GoToRecord , , acFirst
  12.             Me.Requery
  13.             Me!CheckConfirmEntryFrm.Requery
  14.             Me!CheckConfirmVestingFrm.Requery
  15.         Else
  16.         'you are on some other record
  17.             DoCmd.GoToRecord , , acNext
  18.             Me!CheckConfirmEntryFrm.Requery
  19.         End If
  20.     End With
Feb 18 '14 #5
ADezii
8,834 Expert 8TB
I do not see a problem as long as:
  1. The Recordset supports the AbsolutePosition Property, not all do.
  2. You obtain an 'exact' RecordCount by traversing the Recordset, namely:
    Expand|Select|Wrap|Line Numbers
    1. rst.MoveLast:rst.MoveFirst
  3. You do not use the Object Variable Recordset to refer to an actual Recordset as you have in Code Line# 8:
    Expand|Select|Wrap|Line Numbers
    1. With Recordset
    2.   'code segment
    3. End With
Feb 18 '14 #6
mcupito
294 256MB
So for #3 you're suggesting something like:

Expand|Select|Wrap|Line Numbers
  1. Dim rs as DAO.Recordset
  2. rs = (SELECT * FROM Table)
Instead of referring to the Recordset as just a Recordset Object?
Feb 18 '14 #7
ADezii
8,834 Expert 8TB
I am referring to the use of the Reserved Word Recordset to refer to an actual Recordset Object.
Expand|Select|Wrap|Line Numbers
  1. 'Define Recordset rs
  2. With rs
  3.   'Code segment
  4. End With
  5.  
NOT
Expand|Select|Wrap|Line Numbers
  1. 'Define Recordset Recordset
  2. With Recordset
  3.   'Code segment
  4. End With
  5.  
Feb 18 '14 #8
NeoPa
32,556 Expert Mod 16PB
You cannot set a Recordset variable to SQL like that Mark. Even if it did make sense and have quotes around it to make a string, it would still not be valid code.

You need to open a recordset, and possibly pass the SQL string as a parameter.
Feb 18 '14 #9
mcupito
294 256MB
Okay, I understand now.
Would this work then, NeoPa?
Expand|Select|Wrap|Line Numbers
  1.     Set rs = db.OpenRecordset("SELECT * FROM Table")
Feb 18 '14 #10
NeoPa
32,556 Expert Mod 16PB
Fundamentally - yes.

db would have to be set to a valid, open, database. rs would have to be usable as a Recordset variable. Table would have to be a valid table name. "Table" isn't usable without the [] - but that's just the details.
Feb 18 '14 #11
mcupito
294 256MB
Got it. Thanks for your time NeoPa and ADezii.
Feb 18 '14 #12

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

Similar topics

29
by: RAY | last post by:
Hi , my boss has asked I sit in on an interview this afternoon and that I create some interview questions on the person's experience. What is C++ used for and why would a company benefit from...
13
by: Peter Kirk | last post by:
Hi there, can someone tell me what exactly a "property" is in a C# class? As far as I can see it is "two methods" - ie a getter and a setter for an instance variable. What is the difference...
27
by: sklett | last post by:
I just found myself doing something I haven't before: <code> public uint Duration { get { uint duration = 0; foreach(Thing t in m_things) { duration += t.Duration;
8
by: stephen | last post by:
Hi, I make use of properties to store values that are relevant to the page but this time I am posting the page to itself and the values are Zero or null (they disappear). is there any other way...
10
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset...
9
by: superd052 | last post by:
So I'm having a little trouble with the Recordset.AbsolutePosition property, and similarly, the RecordsetClone.AbsolutePosition property in Access 2007. Here's what I'm trying to accomplish: I...
6
by: Trompomerson | last post by:
Hello guys, I am running the script below and am able to load my recordset and cycle through the values in the fields. However I want to use the .AbsolutePosition property to help place the data...
3
by: SanjivaniPant | last post by:
Hello, if I set disabled to true for my frame then will it mean I am stopping the frame from tab ordering? ~Sanjivani
1
by: mk | last post by:
It seems like getter is defined in such way that it passes only 'self': class FunDict(dict): def __init__(self): self.fundict = dict() def fget(self, fun): return fundict
10
Seth Schrock
by: Seth Schrock | last post by:
I have been studying VBA for Access, and the latest chapter was on class modules. So far, I think that I have a pretty good grasp on how to create one (at least for a beginner). However, the point...
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: 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:
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?
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:
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.