ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to format a date to be used in sqlstring in excel 2007? (https://www.excelbanter.com/excel-programming/403331-how-format-date-used-sqlstring-excel-2007-a.html)

ragup001

how to format a date to be used in sqlstring in excel 2007?
 
I have a startdate in cell a1 as 12/1/2006 and enddate in cell a2 as
12/31/2006. These are used as parameters for a sqlstring in excel 2007.
sqlstring = sqlstring & '12/1/2006' ,'12/31/2006'

Excel gives me a run-time error '1004' : SQL syntax error.

Can someone please tell me how to format the dates??

Thanks,

Ragup

mikearelli

how to format a date to be used in sqlstring in excel 2007?
 
Seems to me that whenever I have to deal with dates I have to use # before
and after the date. This may not be the case for you at all, but I'd try:
sqlstring = sqlstring & #12/1/2006# ,#12/31/2006#

"ragup001" wrote:

I have a startdate in cell a1 as 12/1/2006 and enddate in cell a2 as
12/31/2006. These are used as parameters for a sqlstring in excel 2007.
sqlstring = sqlstring & '12/1/2006' ,'12/31/2006'

Excel gives me a run-time error '1004' : SQL syntax error.

Can someone please tell me how to format the dates??

Thanks,

Ragup



All times are GMT +1. The time now is 12:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com