From: Martin on
On Mon, 15 Mar 2010 16:45:45 -0400, "John Simpson"
<jasimp(a)earthlink.net> wrote:

>Can you post the code?
>
This is structure of the code that I'm using in several places in the
program. In the example, the recordset rsMainData is opened when the
program starts and remains open at all times

-------------------------------------------------------------------
Public Sub DoSomething(Msg$)

On Error GoTo DoSomething_ErrorHandler

ParcelNum$ = Mid$(Msg$, 26, 9) ' extract the ParcelNum

rsMainData.Index = "ParcelNum"
rsMainData.Seek "=", ParcelNum$ ' see if we already have it
If rsMainData.NoMatch Then ' if we do not...
rsMainData.AddNew
Else
rsMainData.Edit
End If

rsMainData!UCCNum = Mid$(Msg$, 6, 20)
rsMainData!ParcelNum = ParcelNum$

' a series of statements here assigning
' values to various fields

rsMainData.Update

On Error GoTo 0

Exit Sub

' -----------------------------------------------------
DoSomething_ErrorHandler:

Call UpdateEventLog("Trapped Error (" & Trim$(Str$(Err)) & ") In The
DoSomething Event")
On Error GoTo 0
-------------------------------------------------------------------
From: Nobody on
"Martin" <ironwoodcanyon(a)gmail.com> wrote in message
news:66gsp5p87is3hfngv9evg0fer91655ojmo(a)4ax.com...
> Using VB6 - SP5 MS Access (MDB) data file.
>
> I'm having problems with Error 3021 "No Current Record" error. I have
> reviewed the code - every .Update statement is preceded by either a
> .AddNew or a .Edit.
>
> In an attempt to find where this is occurring, I have every instance
> of data file access (seek/read - edit - addnew - update) surrounded
> with a "On Error GoTo" structure which will log the error to an event
> log that is already part of the program. But the program has crashed
> several times (with Error 3021) since that trapping was added.

Like others suggested, you need to check for EOF, but also for BOF after any
method that moves to another record, such as Move, MoveNext, MovePrevious,
Seek, and after every query. So the code would look something like this:

If rs.BOF And rs.EOF Then
' Recordset is empty, nothing to do
Exit Sub
End If
If rs.BOF Or rs.EOF Then
' No current record, but not empty, go to the first
rs.MoveFirst
End If

If you want a shorter version that combines the above logic of both "If"
statements, use this:

If rs.BOF Xor rs.EOF Then
' Either BOF or EOF is True, but not both, nor they are both False
' No current record and not empty, go to the first record
rs.MoveFirst
End If

You could turn it into a sub or function that you can call from various
places.



> I just read KB106494 which is about this error. There is a sentence in
> there that says: "The On Error statement fails to trap this error."
> Huh ? Is this true?

I couldn't find that KB article either in MSDN October 2001 or online.


From: Henning on

"Nobody" <nobody(a)nobody.com> skrev i meddelandet
news:%23fJTWCJxKHA.5940(a)TK2MSFTNGP02.phx.gbl...
> "Martin" <ironwoodcanyon(a)gmail.com> wrote in message
> news:66gsp5p87is3hfngv9evg0fer91655ojmo(a)4ax.com...
>> Using VB6 - SP5 MS Access (MDB) data file.
>>
>> I'm having problems with Error 3021 "No Current Record" error. I have
>> reviewed the code - every .Update statement is preceded by either a
>> .AddNew or a .Edit.
>>
>> In an attempt to find where this is occurring, I have every instance
>> of data file access (seek/read - edit - addnew - update) surrounded
>> with a "On Error GoTo" structure which will log the error to an event
>> log that is already part of the program. But the program has crashed
>> several times (with Error 3021) since that trapping was added.
>
> Like others suggested, you need to check for EOF, but also for BOF after
> any method that moves to another record, such as Move, MoveNext,
> MovePrevious, Seek, and after every query. So the code would look
> something like this:
>
> If rs.BOF And rs.EOF Then
> ' Recordset is empty, nothing to do
> Exit Sub
> End If
> If rs.BOF Or rs.EOF Then
> ' No current record, but not empty, go to the first
> rs.MoveFirst
> End If
>
> If you want a shorter version that combines the above logic of both "If"
> statements, use this:
>
> If rs.BOF Xor rs.EOF Then
> ' Either BOF or EOF is True, but not both, nor they are both False
> ' No current record and not empty, go to the first record
> rs.MoveFirst
> End If
>
> You could turn it into a sub or function that you can call from various
> places.
>
>
>
>> I just read KB106494 which is about this error. There is a sentence in
>> there that says: "The On Error statement fails to trap this error."
>> Huh ? Is this true?
>
> I couldn't find that KB article either in MSDN October 2001 or online.
>
>

That should be: If (rs.BOF Or rs.EOF) Then.

/Henning


From: Henning on

"Nobody" <nobody(a)nobody.com> skrev i meddelandet
news:%23fJTWCJxKHA.5940(a)TK2MSFTNGP02.phx.gbl...
> "Martin" <ironwoodcanyon(a)gmail.com> wrote in message
> news:66gsp5p87is3hfngv9evg0fer91655ojmo(a)4ax.com...
>> Using VB6 - SP5 MS Access (MDB) data file.
>>
>> I'm having problems with Error 3021 "No Current Record" error. I have
>> reviewed the code - every .Update statement is preceded by either a
>> .AddNew or a .Edit.
>>
>> In an attempt to find where this is occurring, I have every instance
>> of data file access (seek/read - edit - addnew - update) surrounded
>> with a "On Error GoTo" structure which will log the error to an event
>> log that is already part of the program. But the program has crashed
>> several times (with Error 3021) since that trapping was added.
>
> Like others suggested, you need to check for EOF, but also for BOF after
> any method that moves to another record, such as Move, MoveNext,
> MovePrevious, Seek, and after every query. So the code would look
> something like this:
>
> If rs.BOF And rs.EOF Then
> ' Recordset is empty, nothing to do
> Exit Sub
> End If
> If rs.BOF Or rs.EOF Then
> ' No current record, but not empty, go to the first
> rs.MoveFirst
> End If
>
> If you want a shorter version that combines the above logic of both "If"
> statements, use this:
>
> If rs.BOF Xor rs.EOF Then
> ' Either BOF or EOF is True, but not both, nor they are both False
> ' No current record and not empty, go to the first record
> rs.MoveFirst
> End If
>
> You could turn it into a sub or function that you can call from various
> places.
>
>
>
>> I just read KB106494 which is about this error. There is a sentence in
>> there that says: "The On Error statement fails to trap this error."
>> Huh ? Is this true?
>
> I couldn't find that KB article either in MSDN October 2001 or online.
>
>

Ooopppss, just read to the rs.BOF And rs.EOF....
rs.BOF And rs.EOF is true if the *table* is empty

/Henning


From: Paul Clement on
On Mon, 15 Mar 2010 07:16:31 -0700, Martin <ironwoodcanyon(a)gmail.com> wrote:

� Using VB6 - SP5 MS Access (MDB) data file.

� I'm having problems with Error 3021 "No Current Record" error. I have
� reviewed the code - every .Update statement is preceded by either a
� .AddNew or a .Edit.

� In an attempt to find where this is occurring, I have every instance
� of data file access (seek/read - edit - addnew - update) surrounded
� with a "On Error GoTo" structure which will log the error to an event
� log that is already part of the program. But the program has crashed
� several times (with Error 3021) since that trapping was added.

� I just read KB106494 which is about this error. There is a sentence in
� there that says: "The On Error statement fails to trap this error."
� Huh ? Is this true?

� So, I have two questions:

� * does anything else besides .Update cause this error?

� * is it really true that this error is not caught by On Error?



Keep in mind that when you use Seek or FindFirst and there is no match, the pointer in the Recordset
is actually in no mans land. Both BOF and EOF will be False. That's why it's a good idea to perform
a MoveFirst or Move to a current row in the Recordset when NoMatch is True.


Paul
~~~~
Microsoft MVP (Visual Basic)