views:

1912

answers:

2

As in the title I cam across a strange phenomenon. I have a form which contains two subforms. On both subforms I have a button which triggers requery of the relevant subform. If after loading the form, I immediately click on this button (requery the form) I get error "3021: No current record" when I try to save the value of the primary key of the current record in the OnCurrent event to a variable. Strangely enough in the debugger the relevant values are like this:

  Form.CurrentRecord=1
  Form.RecordSet.Absoluteposition=-1
  Form.RecordSet.RecordCount=14
  Form.RecordSet.EOF=False
  Form.RecordSet.BOF=False

Also note, that when the form is loaded, in the load event it still works correctly and the there I can save the primary key value which is the primary key contained in the first record.

Somewhere between Form_Load and me clicking that requery button the status of the form is getting out of synch. I just recently switched from Access 2003 to 2007 and as far as I can remember this error did not happen before (although I might just not click this button right afer load).

For now I have a workaround, but I'd really like to understand how this can happen.

A: 

You have to place the record pointer on a particular record in the form's Recordset via a MoveFirst or whatever. And the return value appears to be zero-based instead of 1-based.

I can't reproduce the error you're getting returning -1. Are you setting the form's recordset to an ADO recordset? If so, that might explain it -- DAO recordsets never return -1 for any of these values, but I believe that before a .MoveLast an ADO RecordCount returns -1. Perhaps AbsolutePosition does the same in ADO.

What are you trying to accomplish? I don't see any utility in using the form's Recordset object when it's so much easier to assign a recordsource and navigate the RecordsetClone (which is much more closely bound to the form's edit/display buffer than the form's Recordset, particularly when the Recordset has been assigned with an ADO recordset).

David-W-Fenton
"but I believe that before a .MoveLast an ADO RecordCount returns -1" -- incorrect. Unlike a DAO recordset, the RecordCount property in ADO does not change merely by navigating the EOF because all rows are fetched; even while fetching rows asynchronously, in the _Progess event the RecordCount shows the final value rather than the number of rows fetched so far. Therefore I can't see how AbsolutePosition could fail to work the same way.
onedaywhen
I can't replicate the reported problem with either the form's .Recordset or the .RecordsetClone. It returns 0 for the first record every time I tested it, so I don't know what the problem. There *is* some circumstance I recall where an ADO recordset's .RecordCount returns -1, but as I don't use ADO often enough to store these things in my brain, I don't recall the exact circumstances.
David-W-Fenton
RecordCount returns -1 when the property is unsupported e.g. either the provider doesn't support it (not the case for ACE/Jet, of course) or the provider settings do not support it e.g. you are using a forward-only cursor. What I am saying is that navigating the EOF will will never cause the RecordCount to change, whether it is -1 or otherwise. IIRC DAO does't always fetch all rows: sometimes you have to navigate the EOF in order to get the correct RecordCount i.e. RecordCount value can change. In ADO, the RecordCount never changes, even when it is -1 (meaning 'unsupported').
onedaywhen
It's Jet whose RecordCount to not be accurate as an exact count of records and it's a result of the "Rushmore" technology that MS got with FoxPro and ported to Access. It starts delivering the first records (for DynaSets, not SnapShots) before the whole recordset is loaded. It's eventually accurate (how long it takes depends on how much data and bandwidth), but a .MoveLast forces it to be accurate. Note that a non-empty DAO Recordset will never return a .RecordCount of 0, so you can test .RecordCount<>0 to know if your recordset returns records.
David-W-Fenton
I take your point but to be clear you are describing Rushmore+DAO behaviour only. Rushmore or no, an ADO recordset's RecordCount always reflects the final amount.
onedaywhen
A: 

If this is ADO, check which OLE DB provider is being used e.g. (guessing)

Debug.Print Form.RecordSet.ActiveConnection.Provider

If by chance it is the 3.51 version, see:

INFO: AbsolutePosition Property with JET Databases in ADO

...if you are using the ACE provider, perhaps it's a regression bug?!

onedaywhen