I have had a code window open all day so I'll post what I was playing with then shut it down.
Version 1 - has error handler, uses append sql statement to append 1 to n as OP asked for:
Code:
Sub AppendRange(n As Integer)
Dim db As DAO.Database
Dim sql As String
Dim cnt As Integer
On Error GoTo errHandler
Set db = CurrentDb
Do Until cnt = n
sql = "INSERT INTO table1 (field1) VALUES(" & cnt + 1 & ")"
db.Execute (sql)
cnt = cnt + 1
Loop
exitHere:
Set db = Nothing
Exit Sub
errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere
End Sub
Version 2 - no error handler, adds to a recordset but does so from x to y
Code:
Sub AppendRange2(lngStart As Long, lngEnd As Long)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim intX As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Table1 WHERE 1 = 0")
For intX = lngStart To lngEnd
With rs
.AddNew
.Fields("Field1") = intX
.Update
End With
Next
rs.Close
Set db = Nothing
Set rs = Nothing
End Sub
Version 2 could also be used with 1 to n as in the first example.
Certainly there are other ways which might be forthcoming.
@WGM I wondered the same thing but only briefly. I once had a situation where a certain amount of info had to be entered to start something but the final Indexed no-dupes value could not be entered until Purchasing provided it. So having to go back to finish something is sometimes necessary; maybe it is so here, maybe not.