appending an Excel worksheet to an existing Access database

Philmer

New Member
Joined
Oct 28, 2004
Messages
36
What I would like to know is on excute of the below code how to delete table2 and remake a table to export excel data to? :oops:

Private Sub Command1_Click()
On Error GoTo errHandler
Dim mExcelFile As String
Dim mAccessFile As String
Dim mWorkSheet As String
Dim mTableName As String
Dim mDataBase As Database
mExcelFile = App.Path & "\Book1.xls"
mAccessFile = App.Path & "\Db2.mdb"
mWorkSheet = "Sheet1"
mTableName = "Table2"
' Below you may use "Excel 7.0" or 8.0 depending on your installable .
Set mDataBase = OpenDatabase(mExcelFile, True, False, "Excel 5.0")
mDataBase.Execute "Select * into [;database=" & mAccessFile & "]." & mTableName & _
" FROM [" & mWorkSheet & "$]"
MsgBox "Done. Use Access to view " & mTableName
Exit Sub
errHandler:
If Err.Number = 3010 Then
MsgBox mTableName & " already exist." & vbCrLf & _
"Delete " & mTableName & " first or use another table name."
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Re: appending an Excel worksheet to an existing Access datab

I use something like this that deletes all the records from the table but leaves the structure ready to add new records.
Code:
CurrentDb.Execute ("DELETE MyTableName.* FROM MyTableName;")
 
Upvote 0
Re: appending an Excel worksheet to an existing Access datab

BrianB,
I tried your statement


code:
--------------------------------------------------------------------------------

CurrentDb.Execute ("DELETE MyTableName.* FROM MyTableName;")

--------------------------------------------------------------------------------

changed to this

mDataBase.Execute ("DELETE mTableName.* FROM mDataBase;")
but does not work any ideas?? :rolleyes:
 
Upvote 0
What is the actual name of the table?
 
Upvote 0

Forum statistics

Threads
1,221,825
Messages
6,162,190
Members
451,752
Latest member
majbizzaki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top