Solved

Why absoluteposition = -1

Posted on 2006-10-31
14
444 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

623 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