how to format a date to be used in sqlstring in excel 2007- contd

R

ragup001

Thanks, but how would you format the field and use it in sqlstring ??
Dim a as String
Dim b as String

a = Range("A1").Select
b = Range("A2").Select

(A1 contains 12/1/2006 and A contains 12/31/2006)

Is it this?? sqlstring = sqlstring #a#,#b#

Thanks in advance.


In any case I am getting an error. Any help is much appreciated.

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#
 
S

sebastienm

Hi,
it depends on the database. MS Access uses the syntax
# <date> #
as date literal. For most database you can enclose the date in single quote:
SELECT ... FROM ... WHERE invoiceDate = '12/1/2006'

eg:
dim sql as string
Dim strDate as String

strDate = Range("A1").Text
sql = "SELECT ... FROM .... WHERE InvoiceDate = '" & strDate & "'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top