sql - Run time error: 3021 No current record found in multiple table recordset loop -


i have form filled questions different equipment. user selects equipment type answers questions each category of tools. each tool category table. please see picture example.

enter image description here

i attempting add new record each table using autonumber linekey table id, primary keys. getting a:

3021 error `no current record found'

when looping through each table adding new record. if run code errors out in first loop @ rec.edit. if walk through code breaks goes through first table loop errors out @ rec.edit second table. not sure missing here.

code:

private sub btnupdatabase_click()     dim integer, j integer, e integer, id integer     dim db database     dim rec recordset     dim value string      set db = currentdb      'create record id "key" in linekey table     set rec = db.openrecordset("select * linekeys")     rec.addnew         rec("line") = me.txtline.value         rec("part number") = me.txtpartnumber.value         rec("equipment") = me.cmbequip.value     rec.update      set rec = currentdb.openrecordset("select @@identity")     id = rec(0)     set rec = nothing      select case cmbequip.value          case "op10 lathe"             dim strarray(0 6) string               strarray(0) = "tool holders"               strarray(1) = "chuck jaws"               strarray(2) = "jaw grippers"               strarray(3) = "drawbars"               strarray(4) = "actuators"               strarray(5) = "chatter pin"               strarray(6) = "chatter pin spring"              j = 0             e = 0 6                 set rec = db.openrecordset("select * [" & strarray(e) & "]")                 rec.addnew                 rec.fields("id") = id                  = 1 7                     rec.edit                     rec.fields("a" & & "") = me.controls("cmb" & j & & "").value                     rec.update                 next                  j = j + 1                  set rec = nothing             next      end select      set rec = nothing     set db = nothing  end sub 

possibly, conflating .addnew , .edit processes first not closed , hence record locked.

consider replacing .edit , move .update outside nested for loop. updating entire row in 1 call , not individual columns iteratively in loop. can simplify outer array looping:

      each e in array("tool holders", "chuck jaws", "jaw grippers", "drawbars", _                           "actuators", "chatter pin", "chatter pin spring")             set rec = db.openrecordset("select * [" & e & "]")              rec.addnew             rec.fields("id") = id             = 1 7                 rec.fields("a" & & "") = me.controls("cmb" & j & & "").value             next             rec.update              j = j + 1             set rec = nothing         next e 

once again, advise not storing separate, similarly-structured tables different values of typology such tool categories. incorporate 1 tool table without many (if any) looping. in way, not change schema new categories , storage more efficient many rows inexpensive compared many tables.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -