Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Date format in Excel query

Hi Group.
I created this query with Excel Macro, and it works.
Then I put a date in a cell in Excel, and assigned the value to Variable
StartDate, and it works.
Now I want to put the StartDate into the WHERE instead of 2005-01-04, but
that does NOT work.
Any Ideas ?

"SELECT DebJournal.Konto, DebJournal.Dato, DebJournal.Varebeløb" & Chr(13) &
"" & _
Chr(10) & "FROM DebJournal DebJournal" & Chr(13) & "" & Chr(10) &
"WHERE (DebJournal.Dato={d '2005-01-04'})" & Chr(13) & "" & Chr(10) & "ORDER
BY DebJournal.Konto, DebJournal.Dato" _
)
.Refresh BackgroundQuery:=False

--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Date format in Excel query

"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr


--
Regards,
Tom Ogilvy

"Peter Hesselager" wrote:

Hi Group.
I created this query with Excel Macro, and it works.
Then I put a date in a cell in Excel, and assigned the value to Variable
StartDate, and it works.
Now I want to put the StartDate into the WHERE instead of 2005-01-04, but
that does NOT work.
Any Ideas ?

"SELECT DebJournal.Konto, DebJournal.Dato, DebJournal.Varebeløb" & Chr(13) &
"" & _
Chr(10) & "FROM DebJournal DebJournal" & Chr(13) & "" & Chr(10) &
"WHERE (DebJournal.Dato={d '2005-01-04'})" & Chr(13) & "" & Chr(10) & "ORDER
BY DebJournal.Konto, DebJournal.Dato" _
)
.Refresh BackgroundQuery:=False

--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Date format in Excel query

Sorry, it didn´t work yet.

Here is the complete statement after implementing your suggestion.
I wonder, if it is the national default for dates, that is causing the
problem ?

Dim StartDate As Date
StartDate = Range("H1").Value

With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=C5
IMBOX;DBQ=c:\c5-4-sp0-hf5\c5data.imb;CODEPAGE=1252;CHARTYPE=VARCHAR;NAME CASE=Unchanged;DISPLAYNAME=DICT;HIGHASCII=TRUE;B" _
), Array("LANKISNULL=FALSE;DEBUG=FALSE;"))
.CommandText = Array( _
"SELECT DebJournal.Konto, DebJournal.Dato, DebJournal.Varebeløb" &
Chr(13) & "" & _
Chr(10) & "FROM DebJournal DebJournal" & Chr(13) & "" & Chr(10) &
"WHERE (DebJournal.Dato={'" & Format(StartDate, "yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr(10) & "ORDER BY DebJournal.Konto, DebJournal.Dato" _
)
.Refresh BackgroundQuery:=False
End With

--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps



"Tom Ogilvy" skrev:

"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr


--
Regards,
Tom Ogilvy


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Date format in Excel query

"WHERE (DebJournal.Dato={d '2005-01-04'})"
is the model

I gave you
"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &

iIf you look closely, you can see that when I was editing your original
string, a character or two got inadvertently deleted. (d space)

"WHERE (DebJournal.Dato={d '" & format(StartDate,"yyyy-mm-dd") & "'})" &

so now we test out the revision:

Sub ABC()
Dim StartDate As Date
s1 = "WHERE (DebJournal.Dato={d '2005-01-04'})"
StartDate = CDate("01/04/2005")
s = "WHERE (DebJournal.Dato={d '" & Format(StartDate, "yyyy-mm-dd") & "'})"
Debug.Print s
Debug.Print s1
End Sub

produces:

WHERE (DebJournal.Dato={d '2005-01-04'})
WHERE (DebJournal.Dato={d '2005-01-04'})

Try it that way. Sorry for the editing error.

--
Regards,
Tom Ogilvy



"Peter Hesselager" wrote:

Sorry, it didn´t work yet.

Here is the complete statement after implementing your suggestion.
I wonder, if it is the national default for dates, that is causing the
problem ?

Dim StartDate As Date
StartDate = Range("H1").Value

With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=C5
IMBOX;DBQ=c:\c5-4-sp0-hf5\c5data.imb;CODEPAGE=1252;CHARTYPE=VARCHAR;NAME CASE=Unchanged;DISPLAYNAME=DICT;HIGHASCII=TRUE;B" _
), Array("LANKISNULL=FALSE;DEBUG=FALSE;"))
.CommandText = Array( _
"SELECT DebJournal.Konto, DebJournal.Dato, DebJournal.Varebeløb" &
Chr(13) & "" & _
Chr(10) & "FROM DebJournal DebJournal" & Chr(13) & "" & Chr(10) &
"WHERE (DebJournal.Dato={'" & Format(StartDate, "yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr(10) & "ORDER BY DebJournal.Konto, DebJournal.Dato" _
)
.Refresh BackgroundQuery:=False
End With

--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps



"Tom Ogilvy" skrev:

"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr


--
Regards,
Tom Ogilvy


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Date format in Excel query

Hi
That did the trick !
Thank's !

I have tried to find info on how to build / edit these formula's - would you
have a link ??
--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps



"Tom Ogilvy" skrev:

"WHERE (DebJournal.Dato={d '2005-01-04'})"
is the model

I gave you
"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &

iIf you look closely, you can see that when I was editing your original
string, a character or two got inadvertently deleted. (d space)

"WHERE (DebJournal.Dato={d '" & format(StartDate,"yyyy-mm-dd") & "'})" &

so now we test out the revision:

Sub ABC()
Dim StartDate As Date
s1 = "WHERE (DebJournal.Dato={d '2005-01-04'})"
StartDate = CDate("01/04/2005")
s = "WHERE (DebJournal.Dato={d '" & Format(StartDate, "yyyy-mm-dd") & "'})"
Debug.Print s
Debug.Print s1
End Sub

produces:

WHERE (DebJournal.Dato={d '2005-01-04'})
WHERE (DebJournal.Dato={d '2005-01-04'})

Try it that way. Sorry for the editing error.

--
Regards,
Tom Ogilvy



"Peter Hesselager" wrote:

Sorry, it didn´t work yet.

Here is the complete statement after implementing your suggestion.
I wonder, if it is the national default for dates, that is causing the
problem ?

Dim StartDate As Date
StartDate = Range("H1").Value

With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=C5
IMBOX;DBQ=c:\c5-4-sp0-hf5\c5data.imb;CODEPAGE=1252;CHARTYPE=VARCHAR;NAME CASE=Unchanged;DISPLAYNAME=DICT;HIGHASCII=TRUE;B" _
), Array("LANKISNULL=FALSE;DEBUG=FALSE;"))
.CommandText = Array( _
"SELECT DebJournal.Konto, DebJournal.Dato, DebJournal.Varebeløb" &
Chr(13) & "" & _
Chr(10) & "FROM DebJournal DebJournal" & Chr(13) & "" & Chr(10) &
"WHERE (DebJournal.Dato={'" & Format(StartDate, "yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr(10) & "ORDER BY DebJournal.Konto, DebJournal.Dato" _
)
.Refresh BackgroundQuery:=False
End With

--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps



"Tom Ogilvy" skrev:

"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr


--
Regards,
Tom Ogilvy




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Date format in Excel query

for the query part, any book on SQL.

for the connection strings

http://www.carlprothman.net/

Look under Technology, then connection strings

--
Regards,
Tom Ogilvy


"Peter Hesselager" wrote:

Hi
That did the trick !
Thank's !

I have tried to find info on how to build / edit these formula's - would you
have a link ??
--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps



"Tom Ogilvy" skrev:

"WHERE (DebJournal.Dato={d '2005-01-04'})"
is the model

I gave you
"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &

iIf you look closely, you can see that when I was editing your original
string, a character or two got inadvertently deleted. (d space)

"WHERE (DebJournal.Dato={d '" & format(StartDate,"yyyy-mm-dd") & "'})" &

so now we test out the revision:

Sub ABC()
Dim StartDate As Date
s1 = "WHERE (DebJournal.Dato={d '2005-01-04'})"
StartDate = CDate("01/04/2005")
s = "WHERE (DebJournal.Dato={d '" & Format(StartDate, "yyyy-mm-dd") & "'})"
Debug.Print s
Debug.Print s1
End Sub

produces:

WHERE (DebJournal.Dato={d '2005-01-04'})
WHERE (DebJournal.Dato={d '2005-01-04'})

Try it that way. Sorry for the editing error.

--
Regards,
Tom Ogilvy



"Peter Hesselager" wrote:

Sorry, it didn´t work yet.

Here is the complete statement after implementing your suggestion.
I wonder, if it is the national default for dates, that is causing the
problem ?

Dim StartDate As Date
StartDate = Range("H1").Value

With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=C5
IMBOX;DBQ=c:\c5-4-sp0-hf5\c5data.imb;CODEPAGE=1252;CHARTYPE=VARCHAR;NAME CASE=Unchanged;DISPLAYNAME=DICT;HIGHASCII=TRUE;B" _
), Array("LANKISNULL=FALSE;DEBUG=FALSE;"))
.CommandText = Array( _
"SELECT DebJournal.Konto, DebJournal.Dato, DebJournal.Varebeløb" &
Chr(13) & "" & _
Chr(10) & "FROM DebJournal DebJournal" & Chr(13) & "" & Chr(10) &
"WHERE (DebJournal.Dato={'" & Format(StartDate, "yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr(10) & "ORDER BY DebJournal.Konto, DebJournal.Dato" _
)
.Refresh BackgroundQuery:=False
End With

--
Med venlig hilsen
Peter Hesselager-Olesen
SBS-IT Aps



"Tom Ogilvy" skrev:

"WHERE (DebJournal.Dato={'" & format(StartDate,"yyyy-mm-dd") & "'})" &
Chr(13) & "" & Chr


--
Regards,
Tom Ogilvy


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Query and date format IgorM[_2_] Excel Discussion (Misc queries) 3 February 24th 10 05:42 PM
MS Query Date Format scos00 Excel Discussion (Misc queries) 0 October 21st 05 04:58 PM
Excel Query Wizard Date Format aldsv Excel Discussion (Misc queries) 1 May 31st 05 12:44 PM
Excel 2000 date format cannot be set to Australian date format Brian Jones Excel Discussion (Misc queries) 1 March 30th 05 06:03 AM
Date format - ADO query Access to Excel gocush[_29_] Excel Programming 1 January 24th 05 09:04 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"