Run-time error 3021

P

PK

When I run the following code in an Access module (and in
V6, too) I get the following error.

The error occurs right near the end of the code. I've
indicated which line.

This is a simplified version of the original code. It
looks a bit pointless as it stands, but the intention in
the original code is to create two initially identical
recordsets. The first rs is directly bound to the source
data. The second rs is the one which users will change
(via a Data Grid). After some validation checks on the
changes, the changes to the second rs will be transferred
to the first rs (and therefore to the source data).

Thanks for your help.

PK

ERROR MESSAGE
Run-time error '3021':
Either BOF or EOF is True or the current record has been
deleted.
Requested operation requires a current record.

CODE
Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = I
.Fields(1) = Chr(96 + I)
.Update
rs1.MoveNext
Loop

rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields(1) '**ERROR**
Loop
End With
 
D

Dan Artuso

Hi,
This could be what's happening.
Here is a snippet from help:

Searches a Recordset for the record that satisfies the specified criteria.
If the criteria is met, the recordset position is set on the found record; otherwise,
the position is set on the end of the recordset.

Now, I'm not clear whether that means it ends up positioned on the last record or
whether EOF is then True. In any case, you can see that if there is no match, your
recordset position is no longer where it was, so your loop becomes ineffective if there
is no match on the first record. I assume that leaving out:
rs1.MoveNext
was just a typo.
 
P

PK

Dan,

How embarassing. Sorry, but my original code was incorrect.

But the problem persists, even with correct code.

The two recordsets should have identical data. In that
case, the Find method should be successful - but it isn't.

Here is the revised code. It should work, but I get same
error, at the same point in the code.

Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop
rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields(1) '**ERROR**
rs1.MoveNext
Loop
End With
-----Original Message-----
Hi,
This could be what's happening.
Here is a snippet from help:

Searches a Recordset for the record that satisfies the specified criteria.
If the criteria is met, the recordset position is set on the found record; otherwise,
the position is set on the end of the recordset.

Now, I'm not clear whether that means it ends up
positioned on the last record or
whether EOF is then True. In any case, you can see that if there is no match, your
recordset position is no longer where it was, so your
loop becomes ineffective if there
is no match on the first record. I assume that leaving out:
rs1.MoveNext
was just a typo.

--
HTH
Dan Artuso, Access MVP


When I run the following code in an Access module (and in
V6, too) I get the following error.

The error occurs right near the end of the code. I've
indicated which line.

This is a simplified version of the original code. It
looks a bit pointless as it stands, but the intention in
the original code is to create two initially identical
recordsets. The first rs is directly bound to the source
data. The second rs is the one which users will change
(via a Data Grid). After some validation checks on the
changes, the changes to the second rs will be transferred
to the first rs (and therefore to the source data).

Thanks for your help.

PK

ERROR MESSAGE
Run-time error '3021':
Either BOF or EOF is True or the current record has been
deleted.
Requested operation requires a current record.

CODE
Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = I
.Fields(1) = Chr(96 + I)
.Update
rs1.MoveNext
Loop

rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields (1) '**ERROR**
Loop
End With


.
 
D

Dan Artuso

Hi,
You should step through the code to see what the values are.
The thing I was trying to point out is that it sounds like EOF and/or BOF is true
for rs2 when you try and and display the values with your MsgBox, hence the error.
In the code below, nothing ever gets added to rs2 so of course it will be empty.

--
HTH
Dan Artuso, Access MVP


PK said:
Dan,

How embarassing. Sorry, but my original code was incorrect.

But the problem persists, even with correct code.

The two recordsets should have identical data. In that
case, the Find method should be successful - but it isn't.

Here is the revised code. It should work, but I get same
error, at the same point in the code.

Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop
rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields(1) '**ERROR**
rs1.MoveNext
Loop
End With
-----Original Message-----
Hi,
This could be what's happening.
Here is a snippet from help:

Searches a Recordset for the record that satisfies the specified criteria.
If the criteria is met, the recordset position is set on the found record; otherwise,
the position is set on the end of the recordset.

Now, I'm not clear whether that means it ends up
positioned on the last record or
whether EOF is then True. In any case, you can see that if there is no match, your
recordset position is no longer where it was, so your
loop becomes ineffective if there
is no match on the first record. I assume that leaving out:
rs1.MoveNext
was just a typo.

--
HTH
Dan Artuso, Access MVP


When I run the following code in an Access module (and in
V6, too) I get the following error.

The error occurs right near the end of the code. I've
indicated which line.

This is a simplified version of the original code. It
looks a bit pointless as it stands, but the intention in
the original code is to create two initially identical
recordsets. The first rs is directly bound to the source
data. The second rs is the one which users will change
(via a Data Grid). After some validation checks on the
changes, the changes to the second rs will be transferred
to the first rs (and therefore to the source data).

Thanks for your help.

PK

ERROR MESSAGE
Run-time error '3021':
Either BOF or EOF is True or the current record has been
deleted.
Requested operation requires a current record.

CODE
Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = I
.Fields(1) = Chr(96 + I)
.Update
rs1.MoveNext
Loop

rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields (1) '**ERROR**
Loop
End With


.
 
P

PK

Dan,

Thanks for your help so far. Sorry if I'm missing the
point, but....

I agree that in the Msgbox line, the EOF is true, but I
don't understand why. rs2 is not empty, because it gets
filled during this loop:
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop

It must be the Find method which isn't working, because if
you replace the last Do loop with the following code, you
step successfully thru rs2:

rs2.MoveFirst
Do While rs2.EOF = False
MsgBox rs2.Fields(0) & " - " & rs2.Fields(1)
rs2.MoveNext
Loop

When the program runs through this loop, the first Msgbox
displays the record with Field0 = 1. But using the
original code the line rs2.Find "Field0 = 1" returns EOF.

I'm a bit confused.

PK
-----Original Message-----
Hi,
You should step through the code to see what the values are.
The thing I was trying to point out is that it sounds like EOF and/or BOF is true
for rs2 when you try and and display the values with your MsgBox, hence the error.
In the code below, nothing ever gets added to rs2 so of course it will be empty.

--
HTH
Dan Artuso, Access MVP


Dan,

How embarassing. Sorry, but my original code was incorrect.

But the problem persists, even with correct code.

The two recordsets should have identical data. In that
case, the Find method should be successful - but it isn't.

Here is the revised code. It should work, but I get same
error, at the same point in the code.

Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop
rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields (1) '**ERROR**
rs1.MoveNext
Loop
End With
-----Original Message-----
Hi,
This could be what's happening.
Here is a snippet from help:

Searches a Recordset for the record that satisfies the specified criteria.
If the criteria is met, the recordset position is set
on
the found record; otherwise,
the position is set on the end of the recordset.

Now, I'm not clear whether that means it ends up
positioned on the last record or
whether EOF is then True. In any case, you can see that if there is no match, your
recordset position is no longer where it was, so your
loop becomes ineffective if there
is no match on the first record. I assume that leaving out:
rs1.MoveNext
was just a typo.

--
HTH
Dan Artuso, Access MVP


When I run the following code in an Access module
(and
in
V6, too) I get the following error.

The error occurs right near the end of the code. I've
indicated which line.

This is a simplified version of the original code. It
looks a bit pointless as it stands, but the intention in
the original code is to create two initially identical
recordsets. The first rs is directly bound to the source
data. The second rs is the one which users will change
(via a Data Grid). After some validation checks on the
changes, the changes to the second rs will be transferred
to the first rs (and therefore to the source data).

Thanks for your help.

PK

ERROR MESSAGE
Run-time error '3021':
Either BOF or EOF is True or the current record has been
deleted.
Requested operation requires a current record.

CODE
Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = I
.Fields(1) = Chr(96 + I)
.Update
rs1.MoveNext
Loop

rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields (1) '**ERROR**
Loop
End With


.


.
 
D

Dan Artuso

HI,
Okay, I've looked over the code from your original post.
After you finish populating rs2, it's positioned where you left it,
at the 2nd record.
So, you then move rs1 to the first record.
When you do your Find, you don't specify where you want your search
to begin, so I beleive the default is from the current record forward.
Because you're positioned on the second record, it will not find a match
and then postion rs2 at EOF.

Try positioning rs2 on the first record.

--
HTH
Dan Artuso, Access MVP


PK said:
Dan,

Thanks for your help so far. Sorry if I'm missing the
point, but....

I agree that in the Msgbox line, the EOF is true, but I
don't understand why. rs2 is not empty, because it gets
filled during this loop:
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop

It must be the Find method which isn't working, because if
you replace the last Do loop with the following code, you
step successfully thru rs2:

rs2.MoveFirst
Do While rs2.EOF = False
MsgBox rs2.Fields(0) & " - " & rs2.Fields(1)
rs2.MoveNext
Loop

When the program runs through this loop, the first Msgbox
displays the record with Field0 = 1. But using the
original code the line rs2.Find "Field0 = 1" returns EOF.

I'm a bit confused.

PK
-----Original Message-----
Hi,
You should step through the code to see what the values are.
The thing I was trying to point out is that it sounds like EOF and/or BOF is true
for rs2 when you try and and display the values with your MsgBox, hence the error.
In the code below, nothing ever gets added to rs2 so of course it will be empty.

--
HTH
Dan Artuso, Access MVP


Dan,

How embarassing. Sorry, but my original code was incorrect.

But the problem persists, even with correct code.

The two recordsets should have identical data. In that
case, the Find method should be successful - but it isn't.

Here is the revised code. It should work, but I get same
error, at the same point in the code.

Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop
rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields (1) '**ERROR**
rs1.MoveNext
Loop
End With
-----Original Message-----
Hi,
This could be what's happening.
Here is a snippet from help:

Searches a Recordset for the record that satisfies the
specified criteria.
If the criteria is met, the recordset position is set on
the found record; otherwise,
the position is set on the end of the recordset.

Now, I'm not clear whether that means it ends up
positioned on the last record or
whether EOF is then True. In any case, you can see that
if there is no match, your
recordset position is no longer where it was, so your
loop becomes ineffective if there
is no match on the first record. I assume that leaving
out:
rs1.MoveNext
was just a typo.

--
HTH
Dan Artuso, Access MVP


When I run the following code in an Access module (and
in
V6, too) I get the following error.

The error occurs right near the end of the code. I've
indicated which line.

This is a simplified version of the original code. It
looks a bit pointless as it stands, but the intention in
the original code is to create two initially identical
recordsets. The first rs is directly bound to the source
data. The second rs is the one which users will change
(via a Data Grid). After some validation checks on the
changes, the changes to the second rs will be
transferred
to the first rs (and therefore to the source data).

Thanks for your help.

PK

ERROR MESSAGE
Run-time error '3021':
Either BOF or EOF is True or the current record has been
deleted.
Requested operation requires a current record.

CODE
Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = I
.Fields(1) = Chr(96 + I)
.Update
rs1.MoveNext
Loop

rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields
(1) '**ERROR**
Loop
End With


.


.
 
P

PK

Well, obviously!

I would never have thought of that in a million years!

Thanks for your help, Dan.

PK
-----Original Message-----
HI,
Okay, I've looked over the code from your original post.
After you finish populating rs2, it's positioned where you left it,
at the 2nd record.
So, you then move rs1 to the first record.
When you do your Find, you don't specify where you want your search
to begin, so I beleive the default is from the current record forward.
Because you're positioned on the second record, it will not find a match
and then postion rs2 at EOF.

Try positioning rs2 on the first record.

--
HTH
Dan Artuso, Access MVP


Dan,

Thanks for your help so far. Sorry if I'm missing the
point, but....

I agree that in the Msgbox line, the EOF is true, but I
don't understand why. rs2 is not empty, because it gets
filled during this loop:
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop

It must be the Find method which isn't working, because if
you replace the last Do loop with the following code, you
step successfully thru rs2:

rs2.MoveFirst
Do While rs2.EOF = False
MsgBox rs2.Fields(0) & " - " & rs2.Fields(1)
rs2.MoveNext
Loop

When the program runs through this loop, the first Msgbox
displays the record with Field0 = 1. But using the
original code the line rs2.Find "Field0 = 1" returns EOF.

I'm a bit confused.

PK
-----Original Message-----
Hi,
You should step through the code to see what the values are.
The thing I was trying to point out is that it sounds like EOF and/or BOF is true
for rs2 when you try and and display the values with
your
MsgBox, hence the error.
In the code below, nothing ever gets added to rs2 so of course it will be empty.

--
HTH
Dan Artuso, Access MVP


Dan,

How embarassing. Sorry, but my original code was incorrect.

But the problem persists, even with correct code.

The two recordsets should have identical data. In that
case, the Find method should be successful - but it isn't.

Here is the revised code. It should work, but I get same
error, at the same point in the code.

Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = rs1("Field0") 'Changed
.Fields(1) = rs1("Field1") 'Changed
.Update
rs1.MoveNext
Loop
rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields (1) '**ERROR**
rs1.MoveNext
Loop
End With
-----Original Message-----
Hi,
This could be what's happening.
Here is a snippet from help:

Searches a Recordset for the record that satisfies the
specified criteria.
If the criteria is met, the recordset position is
set
on
the found record; otherwise,
the position is set on the end of the recordset.

Now, I'm not clear whether that means it ends up
positioned on the last record or
whether EOF is then True. In any case, you can see that
if there is no match, your
recordset position is no longer where it was, so your
loop becomes ineffective if there
is no match on the first record. I assume that leaving
out:
rs1.MoveNext
was just a typo.

--
HTH
Dan Artuso, Access MVP


When I run the following code in an Access module (and
in
V6, too) I get the following error.

The error occurs right near the end of the code. I've
indicated which line.

This is a simplified version of the original code. It
looks a bit pointless as it stands, but the intention in
the original code is to create two initially identical
recordsets. The first rs is directly bound to the source
data. The second rs is the one which users will change
(via a Data Grid). After some validation checks on the
changes, the changes to the second rs will be
transferred
to the first rs (and therefore to the source data).

Thanks for your help.

PK

ERROR MESSAGE
Run-time error '3021':
Either BOF or EOF is True or the current record
has
been
deleted.
Requested operation requires a current record.

CODE
Dim rs1, rs2 As Recordset
Dim I As Integer

Set rs1 = New Recordset
Set rs2 = New Recordset

With rs1
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
For I = 1 To 10
.AddNew
.Fields(0) = I
.Fields(1) = Chr(64 + I)
.Update
Next I
.MoveFirst
For I = 1 To 10
.Find "[Field0] = " & I
Next
End With

With rs2
.CursorLocation = adUseClient
.Fields.Append "Field0", adInteger
.Fields.Append "Field1", adVarChar, 40,
adFldIsNullable
.Open , , adOpenDynamic, adLockOptimistic
rs1.MoveFirst
Do While rs1.EOF = False
.AddNew
.Fields(0) = I
.Fields(1) = Chr(96 + I)
.Update
rs1.MoveNext
Loop

rs1.MoveFirst
Do While rs1.EOF = False
.Find "[Field0] = " & rs1("Field0")
MsgBox .Fields(0) & " - " & .Fields
(1) '**ERROR**
Loop
End With


.



.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top