To set the context (there's a lot going on in this app with lots of code and tables but I have boiled the problem down to this situation):
0. DB is in 2000 format being developed under Access 2003.
1.I have a fairly self-contained subform (no Master/Child in effect) that is in continous mode disaply bound to a single table through a straight on SQL-type statement set on the RecordSource attribute, pretty much like Select Items from Table.
2.I should also note there are controls on the parent form which set filters for the subform - one combo box setting the sort by field and the other setting the criteria (e.g. a box to hold the predicate for a Like "stuff" statement.
And a "go" button which sets Filters On for the subform and a "reset" button to turn it off. (I don't believe this is part of problem but I have read there are sometimes problems associated with filters so included this for completeness). As will be explained below I have worked with turning the filter on and off before the problem actions described below to no avail.
3.There is an unbound "Edit" command button on the Detail section so that each record displayed has a control button to request authorized "editing" actions for that record. The OnClick event routine of that command button does the appropriate checking and allows/disallows various user actions including the deletion of the current record. That's where the problem is showing up.
4. when the user clicks the Edit button, the Click routine checks the record and determines based on status/type of record what the user can do. In the case where the only option the user has is to delete the record, a YewNo MsgBox
is popped up to confirm they want to delete.
If they click yes, the Click routine code deletes the current record with:
Me.Recordset.Delete
and the record is deleted. At this point, understandably the Me.Recordset record position is indeterminate (i.e. Me.CurrentRecord or Me.AbsolutePostion are undefined). The
next line of code does a:
Me.Requery
so that the form will refresh the display and by default the focus returns to the first record of the resulting refresh. If I check the FORM's Me.CurrentRecord, it is fine pointing to #1 (fields can be edited, etc). However, randomly and intermittently, the underlying RecordPosition linked to the table is NOT fine and stays indeterminate (i.e. Me.Recordset.CurrentRecord and Me.AbsolutePosition are Null and -1 resp). The next time any action is attempted on the record, there is a "No Current Record" error displayed.
Here's some of the things I have played with:
1. Turning off the Forms filtering before deleting, after deleting but before requerying after the requerying, etc - no change.
2. I have put a for loop delay after the Delete thinking there might be a race condition on the delete (i.e. the requery gets there before the delete completes - although I would hope this would be synchronously queued and dealt with in event queue).
3. I also have Me.Requery on the AfterUpdate event but which usually doesn't fire because the programmatic
Boiled down, I want the user to be able to click on a record and after qualifying code, delete that record, refresh the list and be back on another record still linked to the underlying table correctly.
Has anyone seen this kind of behavior? Am I doing something obviously wrong that's staring me in the face and I can't see it.
I understand that this is most explanation and little code but I hope I've conveyed the essence. It would be too unwieldy to splat all the code out. If this doesn't ring a quick bell with anyone, my next step is to try and creae a simple one-or two-field form with button, etc for a boiled down example and see if the behavior duplicates and if so, will post that code.
Any thougths from anyone?
Thanks,
farmgrown
0. DB is in 2000 format being developed under Access 2003.
1.I have a fairly self-contained subform (no Master/Child in effect) that is in continous mode disaply bound to a single table through a straight on SQL-type statement set on the RecordSource attribute, pretty much like Select Items from Table.
2.I should also note there are controls on the parent form which set filters for the subform - one combo box setting the sort by field and the other setting the criteria (e.g. a box to hold the predicate for a Like "stuff" statement.
And a "go" button which sets Filters On for the subform and a "reset" button to turn it off. (I don't believe this is part of problem but I have read there are sometimes problems associated with filters so included this for completeness). As will be explained below I have worked with turning the filter on and off before the problem actions described below to no avail.
3.There is an unbound "Edit" command button on the Detail section so that each record displayed has a control button to request authorized "editing" actions for that record. The OnClick event routine of that command button does the appropriate checking and allows/disallows various user actions including the deletion of the current record. That's where the problem is showing up.
4. when the user clicks the Edit button, the Click routine checks the record and determines based on status/type of record what the user can do. In the case where the only option the user has is to delete the record, a YewNo MsgBox
is popped up to confirm they want to delete.
If they click yes, the Click routine code deletes the current record with:
Me.Recordset.Delete
and the record is deleted. At this point, understandably the Me.Recordset record position is indeterminate (i.e. Me.CurrentRecord or Me.AbsolutePostion are undefined). The
next line of code does a:
Me.Requery
so that the form will refresh the display and by default the focus returns to the first record of the resulting refresh. If I check the FORM's Me.CurrentRecord, it is fine pointing to #1 (fields can be edited, etc). However, randomly and intermittently, the underlying RecordPosition linked to the table is NOT fine and stays indeterminate (i.e. Me.Recordset.CurrentRecord and Me.AbsolutePosition are Null and -1 resp). The next time any action is attempted on the record, there is a "No Current Record" error displayed.
Here's some of the things I have played with:
1. Turning off the Forms filtering before deleting, after deleting but before requerying after the requerying, etc - no change.
2. I have put a for loop delay after the Delete thinking there might be a race condition on the delete (i.e. the requery gets there before the delete completes - although I would hope this would be synchronously queued and dealt with in event queue).
3. I also have Me.Requery on the AfterUpdate event but which usually doesn't fire because the programmatic
Boiled down, I want the user to be able to click on a record and after qualifying code, delete that record, refresh the list and be back on another record still linked to the underlying table correctly.
Has anyone seen this kind of behavior? Am I doing something obviously wrong that's staring me in the face and I can't see it.
I understand that this is most explanation and little code but I hope I've conveyed the essence. It would be too unwieldy to splat all the code out. If this doesn't ring a quick bell with anyone, my next step is to try and creae a simple one-or two-field form with button, etc for a boiled down example and see if the behavior duplicates and if so, will post that code.
Any thougths from anyone?
Thanks,
farmgrown