Method 'MoveNext' of object 'Recordset' failed

B

Barnabas Mudri

Hi,

I'd like update the table in the opened form and some other tables too by
recordset too.
After I update the data on the form - line 16 - I get an error at line 18 -
Method 'MoveNext' of object 'Recordset' failed
If I delete line 16 it works. why?

thx
Barna

------

1 Dim sz2 As String
2 Dim i As Long
3 Dim aa
4 Dim rs2 As ADODB.Recordset
5 Set rs2 = New ADODB.Recordset
6 i = 2
7 rs.Close
8 Form_SZAMLA_sorok.Recordset.MoveFirst
9 Do
10 If Form_SZAMLA_sorok.szamlazva Then
11 sz2 = "SELECT * FROM MOZGAS"
12 rs2.Open sz2, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
13 aa = Array(Str(Form_SZAMLA.sz_datum), Str(Form_SZAMLA_sorok.m_aruID),
Str(2), Str(Form_SZAMLA.sz_vevo), Str(Form_SZAMLA_sorok.sz_rID),
Str(Form_SZAMLA_sorok.db))
14 rs2.AddNew Array("datum", "aruID", "mozgasID", "vevoID", "rID", "db"),
aa
15 rs2.Close
16 Form_SZAMLA_sorok.sz_szID = i
17 End If
18 Form_SZAMLA_sorok.Recordset.MoveNext
20 Loop Until Form_SZAMLA_sorok.Recordset.EOF
 
J

JohnFol

Is your code running within the Before_Update event?

line 16 is going to place a lock on the forms recordset as you are entering
an edit.
 
K

kevin.witty

Uumm.. this is my first entry into this forum, and my first reply with this
newsreader, so I apologize if I look like an idiot, but....

Is the table in the form bound or unbound? If bound, you need do nothing to
update it: it's done already. If unbound, other methods apply.

Either way, if you need to update other tables, I don't understand why you
want to do recordset stuff. You can construct an SQL statement which says
"update {YourTable} set {FieldName} = {YourValue}, ... where {Criteria}
and DoCmd.runSql {SqlStatement}.

If you feel you must do recordset stuff, your use of arrays just puzzles me.
Why not use something like the following (works best with a class module)

Function AddOrUpd (YourSql as string) 'Field names and values are best set
in a class module
on error goto CheckIt
set rst = currentdb().openrecordset ({YourSql}, dbOpenDynaset) 'YourSql is
the the Sql which selects the records you need
' There may be none
with rst
while not .eof ' Best way I've seen to loop through a dataset
.movefirst ' Needed if you're going to update with dbOpenDynaSet, NOT
needed if you just want to read.
' Don't know why MS decided that dbOpenDynaset needs to be positioned to
the first record
' and everything else is already there.
.edit ' You're going to change a value in the selected record
!FieldName = "SomeValue" ' The ! refers to the field name in the
recordset. Works best with a class module
!etc
.update ' Record the change you made
goto Updated
..AddNew:
.AddNew
!FieldName = "SomeValue" ' The ! refers to the field name in the
recordset. Set all fields necessary for a new record
!etc
.update ' Record the new record

Updated:
.MoveNext 'Move to the next record in the selected records. If you're at
the end, you're at wend
wend ' Keeps on going until .EOF
end with
exit Function
CheckIt:
if err = 3021 then goto AddNew ' Record not found, add it
msgbox err & ": " & err.description
resume next
end Function
 

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