Solved

Why absoluteposition = -1

Posted on 2006-10-31
14
432 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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

756 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