Hi,
I am trying to import data into excel and I am using a DAO copy function to get the data, but I am having a problem with dates, this is what i have tried with the sql string
'strSQL = "SELECT * FROM tblBPData WHERE ((Date)=date()-4);" ' this works
'strSQL = "SELECT * FROM " & TableName & " WHERE ((" & FieldName & ")=date()-4);" 'this works
'strSQL = "SELECT * FROM " & TableName & " WHERE ((" & FieldName & ")=#" & datefield & "#);" ' this doesnt
'strSQL = "SELECT * FROM " & TableName & " WHERE (([" & FieldName & "])=#" & datefield & "#);" ' this doesnt work
strSQL = "SELECT * FROM " & TableName & " WHERE (([" & FieldName & "])=" & datefield & ");"' this doesnt work
the first strsql is taken diretly from an access database and works fine when I use it in excel vba, and pulls the correct data.
second is modified to use the tablename variable and works fine and pulls the data.
as soon as I try to use the date part as a variable it falls over.
date has been defined as date variable or string variable and it still fails
Hope this is of use, Rob.
I am trying to import data into excel and I am using a DAO copy function to get the data, but I am having a problem with dates, this is what i have tried with the sql string
'strSQL = "SELECT * FROM tblBPData WHERE ((Date)=date()-4);" ' this works
'strSQL = "SELECT * FROM " & TableName & " WHERE ((" & FieldName & ")=date()-4);" 'this works
'strSQL = "SELECT * FROM " & TableName & " WHERE ((" & FieldName & ")=#" & datefield & "#);" ' this doesnt
'strSQL = "SELECT * FROM " & TableName & " WHERE (([" & FieldName & "])=#" & datefield & "#);" ' this doesnt work
strSQL = "SELECT * FROM " & TableName & " WHERE (([" & FieldName & "])=" & datefield & ");"' this doesnt work
the first strsql is taken diretly from an access database and works fine when I use it in excel vba, and pulls the correct data.
second is modified to use the tablename variable and works fine and pulls the data.
as soon as I try to use the date part as a variable it falls over.
date has been defined as date variable or string variable and it still fails
Hope this is of use, Rob.