Solved

Why absoluteposition = -1

Posted on 2006-10-31
14
426 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
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.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

856 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