L
Laurence Lombard
Being a newbie to Access I would like clarification on the following
Excel VBA code. The intention is to delete all records in Table1 in
MyDatabase.mdb and reset the autonumber.
Sub TableDeleteRecordsAndResetAutonumber()
Set db = OpenDatabase("C:\Users\MyDocuments\MyDatabase.mdb")
db.Execute "DELETE * FROM Table1" 'Note 1: This works
'DoCmd.runSQL "DELETE * FROM Table1" 'Note 2: gives error "Object
required"
'db.CompactDatabase 'NOTE3 : does not work
' Application.SetOption ("Auto Compact"), 0 'NOTE4 : Does not work
db.Close
Set db = Nothing 'NOTE5
End Sub
NOTE1,2: After much trial and error (1) works. Many posts on the
internet forums use code like (2), but this gives an error "Object
required". What must be done to get (2) to work. I don't understand the
significance of "DoCmd.runSQL"
NOTE 3,4: From what I gather the Compact Database method will reset the
autonumber, so I tried these variations, but they do not work. What must
the code look like. Is there another way to reset the autonumber using
Excel VBA?
NOTE 5: What does this statement do. Why is it necessary/recommended
Many Thanks
Excel VBA code. The intention is to delete all records in Table1 in
MyDatabase.mdb and reset the autonumber.
Sub TableDeleteRecordsAndResetAutonumber()
Set db = OpenDatabase("C:\Users\MyDocuments\MyDatabase.mdb")
db.Execute "DELETE * FROM Table1" 'Note 1: This works
'DoCmd.runSQL "DELETE * FROM Table1" 'Note 2: gives error "Object
required"
'db.CompactDatabase 'NOTE3 : does not work
' Application.SetOption ("Auto Compact"), 0 'NOTE4 : Does not work
db.Close
Set db = Nothing 'NOTE5
End Sub
NOTE1,2: After much trial and error (1) works. Many posts on the
internet forums use code like (2), but this gives an error "Object
required". What must be done to get (2) to work. I don't understand the
significance of "DoCmd.runSQL"
NOTE 3,4: From what I gather the Compact Database method will reset the
autonumber, so I tried these variations, but they do not work. What must
the code look like. Is there another way to reset the autonumber using
Excel VBA?
NOTE 5: What does this statement do. Why is it necessary/recommended
Many Thanks