Hi all,
I want to create a module that exports data to excel. I found some help on the internet but I can't get it to work.
This is my code:
strExcelFile = "H:\TEMP\test.xls"
strWorksheet = "test"
strDB = "H:\TEMP\testdatabas.mdb"
strTable = "tabel"
strQuery = "query"
strString = "Name"
MySql = "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & "].[" & strWorksheet & "] FROM [" & strQuery & "] WHERE [" & strString & " ] = Namn"
Set objDB = CurrentDb()
'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> "" Then Kill strExcelFile
objDB.Execute MySql
objDB.Close
This does not work.
If I change MySql to
MySql = "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & "].[" & strWorksheet & "] FROM [" & strQuery & "]"
Everything works fine.
So, what is wrong with
WHERE [" & strString & " ] = Namn"
I am no stranger to SQL it is the VBA syntax that gives me headache
I want to create a module that exports data to excel. I found some help on the internet but I can't get it to work.
This is my code:
strExcelFile = "H:\TEMP\test.xls"
strWorksheet = "test"
strDB = "H:\TEMP\testdatabas.mdb"
strTable = "tabel"
strQuery = "query"
strString = "Name"
MySql = "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & "].[" & strWorksheet & "] FROM [" & strQuery & "] WHERE [" & strString & " ] = Namn"
Set objDB = CurrentDb()
'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> "" Then Kill strExcelFile
objDB.Execute MySql
objDB.Close
This does not work.
If I change MySql to
MySql = "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & "].[" & strWorksheet & "] FROM [" & strQuery & "]"
Everything works fine.
So, what is wrong with
WHERE [" & strString & " ] = Namn"
I am no stranger to SQL it is the VBA syntax that gives me headache
Last edited: