Deleting records before writing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm transferring Excel spreadsheet to Access table. I have multiple tables.
How ever when I transfer data to existing table, earlier records stays also
in table. How can I delete the record from table before writing? I can't
delete whole table and then create it again, because tables contains
relationships. Can this be made simply with macro or does it require coding?
 
One approach would be to create a delete query. If you are using macros
rather than code, you can run the delete query in a macro.
 
After all I could prefer coding than macros. I just haven't been playing so
much with databases and recordsets in VBA. So, if I only could have little
bit help with those.
 
After all I could prefer coding than macros. I just haven't been playing so
much with databases and recordsets in VBA. So, if I only could have little
bit help with those.

Try either:

DoCmd.RunSQL "DELETE * FROM TableToBeEmptied;"

or, safer but more steps:

Dim db As DAO.Database
Dim qd As DAO.Querydef
On Error GoTo Proc_Error
Set db = CurrentDb
Set qd = db.Querydefs("StoredDeleteQuery")
qd.Execute dbFailOnError
....
Proc_Exit:
Exit Sub
Proc_Error:
<message boxes warning user of error>
Resume Proc_Exit
End Sub


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top