being a novice user not familiar with databases much but trying to export my access table in excel.
i will be highly appreciated if someone can help me in that.i am very new to databases and vba and i hope you wont mind to help my stupid questions.
i have the following code which gives an error when i try to implement it.
Private Sub Command22_Click()
Dim strExcelFile As String
Dim strWorksheet As String
Dim strDB As String
Dim strTable As String
Dim objDB As Database
'Change Based on your needs, or use
'as parameters to the sub
strExcelFile = "C:\My Documents\M.xls" (this is the name of the excel file)
strWorksheet = "sheet1" (this is the name of the sheet in work book)
strDB = "C:\Users\TARIQ\Desktop\w\data_input.accdb" (this is the location where my database file lying)
strTable = "main" ("main" is the name of the table in my data_intput.accdb database)
Set objDB = OpenDatabase(strDB)
'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> "" Then Kill strExcelFile
objDB.Execute _
"SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
"].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
objDB.Close
Set objDB = Nothing
End Sub
as i am no new to the databases so please help me if i am missing something.
regards
A learner