This
Private Sub Form_AfterInsert()
If Me.ID=10 Then
' run code
End If
End Sub
Will look at the ID field (or whatever your autonumber field value is) and won't take into account deleted records but will return the last autonumber value.
If you want to count the exact # of records in the table, you could create a function in a module as such:
Function NumOfRecords() as variant
dim rs as adodb.recordset
set rs = new adodb.recordset
dim strSQL as string
strSQL = "Select * from myTableName"
rs.open strSQL, currentproject.connection, adopenkeyset, adlockreadonly
if rs.eof and rs.bof then
NumOfRecords = 0
else
NumOfRecords = rs.recordcount
end if
rs.close
set rs = nothing
End Funtion
Then you'd call the function in your form coding as such:
If NumOfRecords() >= 10 then
msgbox "recordcount is equal to or greater than 10"
end if
or
msgbox "# of Records = " & NumOfRecords()