2 things you can do when it comes to adding a batch of records where some violate indexes.
- if a table field is set to no dupes, then when running an append query, turn off warnings, run query, and turn back on again. You won't see the warnings and any records that can't be appended are simply skipped. Those that can be are.
- often preferred is to use the Execute method of the CurrentDb object. If you use the dbFailOnError option, you can trap error 3022 in an error handling routine and simply resume next, or if that's not appropriate, don't use the option and hope what needs to be added is. Here's an example of this, including examples of concatenation with variables (n) and error handling routine.
Code:
Sub TestDbExecuteOnIndexedField()
Dim n As Integer
On Error GoTo errHandler
For n = 5 To 7
CurrentDb.Execute "Insert into [tblYourTableName](YourFieldName) Values (" & n & ")", dbFailOnError
Next n
exitHere:
Exit Sub
errHandler:
If Err.Number = 3022 Then
Resume Next
Else
MsgBox "Error " & Err.Number & "; " & Err.Description
Resume exitHere
End If
End Sub
Note: .Execute will accept a stored query rather than a sql statement as the sql argument.
P.S. Since you've 'lost your train of thought', I opted to respond to the issue of the warnings you're getting rather than try to get on board a train that has already left.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.