Solved

Why absoluteposition = -1

Posted on 2006-10-31
14
435 Views
Last Modified: 2008-02-01
I have a form with a filtered recordset. recordcount = 0. I then use code to add a record:

  AllowAdditions = 1
  with recordset
     .Recordset.AddNew
     .Recordset(key) = newID ' this satisfies the filter condition, and the record appears in the form
     .Recordset.update
  end with
  AllowAdditions = 0

At this point I expect absoluteposition to = 0. But it = -1!
No amount of juggling seems to change that.
What am I missing?
0
Comment
Question by:ramrom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +2
14 Comments
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17847760
So you've presumably got a standard bound form with a DAO recordset one way or another yeah? (note to future readers:  As DAO recordsets' absoluteposition is zero based, whereas ADO's aren't :-S)

Is it not a case of needing to push a Me.Requery in there?  Or a rst.MoveFirst?  (Or more ideally, a MoveLast!!)
Seems overkill I know - but I think it's because you have an Absolute position of -1 as soon as you're on the "New Row" record which the Access UI provides (and you're moved to by the underlying recordsets AddNew action).
And that isn't updated (despite the recordset's Update call) until you requery or "move" to a "legitimate" record - even if it's the same one!
0
 
LVL 17

Author Comment

by:ramrom
ID: 17847823
I've tried all of those. No effect.
0
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 250 total points
ID: 17847835
Works for me.

  AllowAdditions = 1

  With Me.Recordset
     .AddNew
     Debug.Print "Pos1" & Recordset.AbsolutePosition  '-1 here
     .Fields("Whatever") = "Whatever"
     .Update
     .MoveLast
  End With
  AllowAdditions = 0

  Debug.Print "Pos2" & Me.Recordset.AbsolutePosition  '0 here
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 20

Expert Comment

by:clarkscott
ID: 17849431
Perhaps adding a record (in code) doesn't necessary focus on the new record.  Therefore, your absolute position is still BOF.

Scott C.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 17849693
Just because you add a record doesn't mean you're on it. Re-filter your recordset

AllowAdditions = 1
  with recordset
     .Recordset.AddNew
     .Recordset(key) = newID ' this satisfies the filter condition, and the record appears in the form
     .Recordset.update
  end with
  AllowAdditions = 0

mefilteron = true
me.filter = me.myID = My New key number
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17851325
This in part from VB Editor Help - Answer Wizard - Absoluteposition

If there is no current record, as when there are no records in the Recordset object, AbsolutePosition returns –1. If the current record is deleted, the AbsolutePosition property value isn't defined, and a trappable error occurs if it's referenced. New records are added to the end of the sequence.

0
 
LVL 17

Author Comment

by:ramrom
ID: 17851347
Me bad. The code I posted was followed by

  with recordset
   .edit
   !x = 2
   .update ' before this AbsolutePosition was 0; following this AbsolutePosition is -1
  end with

So I followed this with a findfirst based on the new record's primary key and now all is well.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17851379
I believe you asked: "Why AbsolutePosition = -1"
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 17851455
Isn't your solution what I suggested? Hmmm

And G did answer your question as asked.

Good Job Leigh! lol

J :o)
0
 
LVL 17

Author Comment

by:ramrom
ID: 17852090
Yeah it's hard at times to pick the answer. Get you next time.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17852119
I'm un-fussed.

Just called the requirements as I saw them.  (Moving from a Absoluteposition of -1, back to a meaningful 0).
If I saw them as something else - then I'd have answered that.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 17852179
I'm unfussed as well...as is G I'm sure....just an odd award. No hard feelings here!! I'm just HTH.
J
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 17852458
Actually Jeff, I suggested it before you did......
s
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17854748
Fussed, un-Fussed, cloaked English - Bah!  All I did was ATFQ.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question