Link to home
Start Free TrialLog in
Avatar of ramrom
ramromFlag for United States of America

asked on

Why absoluteposition = -1

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?
Avatar of Leigh Purvis
Leigh Purvis
Flag of United Kingdom of Great Britain and Northern Ireland image

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!
Avatar of ramrom

ASKER

I've tried all of those. No effect.
ASKER CERTIFIED SOLUTION
Avatar of Leigh Purvis
Leigh Purvis
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perhaps adding a record (in code) doesn't necessary focus on the new record.  Therefore, your absolute position is still BOF.

Scott C.
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
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.

Avatar of ramrom

ASKER

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.
I believe you asked: "Why AbsolutePosition = -1"
Isn't your solution what I suggested? Hmmm

And G did answer your question as asked.

Good Job Leigh! lol

J :o)
Avatar of ramrom

ASKER

Yeah it's hard at times to pick the answer. Get you next time.
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.
I'm unfussed as well...as is G I'm sure....just an odd award. No hard feelings here!! I'm just HTH.
J
Actually Jeff, I suggested it before you did......
s
Fussed, un-Fussed, cloaked English - Bah!  All I did was ATFQ.