How to import from excel to existing table in access

abodayehia

New member
Local time
Today, 23:04
Joined
Jun 22, 2014
Messages
8
Hi guys
i hope that this thread finds you all well .
i am new to MS Access And i am trying to make my way through it . but some times i need help so here i am posting here.
i have a button in a form i want a vba code . when i click on the button i choose
excel file i want to import to table called CardDetails and delete all old data on it and just keep the new data .
Any Suggestions on how to do this? or is there and existing code to do this ?
thanks
 
You'd need to do this in several steps
to locate a file, use the
Application.FileDialog(msoFileDialogFilePicker) method
to clean out old data use
Docmd.RunSQL("DELETE CardDetails.* FROM CardDetails")
to import the located file use
TransferSpreadsheet method

You may want to validate each step to ensure you're not deleting the old data only to find the new data source is corrupt or has no data in it

David
 
Thanks For The Reply

I did most of the methods but i don't know how to validate if the file have data or is corrupted ???
 
try importing the new data into a temp table first, if the recordcount > 0 then, use
Docmd.RunSQL("DELETE CardDetails.* FROM CardDetails")
then run an append query to move the new data from temp into CardDetails table

David
 

Users who are viewing this thread

Back
Top Bottom