Solved

Why absoluteposition = -1

Posted on 2006-10-31
14
395 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now