I have this code working correctly. I have tested it numerous times.
The first time it runs through correctly but each subsequent time it errors out.
I know which line is causing the issue but I don't know why.
I don't change anything in the codes or the form from one test to the other! Help.... It's driving me crazy.
If I go in and delete and type the Me.nonconformanceRecordID when it fails it seems to work again. It doesn't like a cut and paste either. I actually have to retype this section of code.
While writing this post I commented out the 'DoCmd.GoToRecord , , acNewRec and it works but then it doesn't clear the form!
What can you suggest,
Should I use a routine to clear the controls?
Code:Set dbs = CurrentDb Set rst = dbs.OpenRecordset("Problem_Record") 'Form Recordsource = Nonconformance_Record tbl 'Loop through the ItemsSelected in the list box. With Me.lstCAR 'here we are getting the Problemid of the selected Items '********************************* For Each varItem In .ItemsSelected If Not IsNull(varItem) Then rst.AddNew recCnt = recCnt + 1 rst!ProblemID = lstCAR.ItemData(varItem) rst!NonconformanceRecordID = Me.NonconformanceRecordID End If rst.Update Next End With With Me.lstCAR For Each varItm In .ItemsSelected .Selected(varItm) = False Next varItm End With 'DoCmd.GoToRecord , , acNewRec On Error GoTo 0 Exit Sub cmdAddRec_Click_Error: MsgBox "Error " & Err.Number & " in line " & Erl & " (" & Err.Description & ") in procedure cmdAddRec_Click of VBA Document Form_Nonconformance_Record_form" End Sub