I have a form that is filled with questions for different equipment. The user selects the equipment type then answers the questions for each category of tools. Each tool category is a table. Please see picture for example.
I am attempting my to add a new record into each table using a autonumber from the LineKey
table as my ID
, my primary keys. However I am getting a:
3021 error `No current record found'
when I am looping through each table adding the new record. If I run the code it errors out in the first loop at rec.Edit
. If I walk through the code with breaks it goes through the first table loop but then errors out at rec.Edit
for the second table. I am not sure what I am missing here.
CODE:
Private Sub btnUpDatabase_Click()
Dim i As Integer, j As Integer, e As Integer, ID As Integer
Dim db As Database
Dim rec As Recordset
Dim Value As String
Set db = CurrentDb
'Create Record ID "Key" in lineKey table
Set rec = db.OpenRecordset("SELECT * FROM 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 To 6) As 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
For e = 0 To 6
Set rec = db.OpenRecordset("SELECT * FROM [" & strArray(e) & "]")
rec.AddNew
rec.Fields("ID") = ID
For i = 1 To 7
rec.Edit
rec.Fields("A" & i & "") = Me.Controls("cmb" & j & i & "").Value
rec.Update
Next
j = j + 1
Set rec = Nothing
Next
End Select
Set rec = Nothing
Set db = Nothing
End Sub