473,396 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Incorrect Date posting Access 2000 SQL statement

Running MS Access 2000
MS Windows XP Pro

This has caused me a lot of hair loss in the last few days so would
appreciate any help.

I am running code to append/update a local access database from a
remote MS SQL database. The method of determining which records to
append is primarily using the last date an update was carried out; I
appreciate that there is probably a better way of doing this but time
contraints prevent me from doing extensive research and dev at the
moment. Below is a section of code from the procedure where
tblLastUpdate is a 2 field single record table used to store the date
the database was last updated.
Dim dateLastUpdate As Date
Dim dateNewUpdate As Date
Dim dateCurrentDate As Date
Dim stUpdateLastUpdateSQL As String
dateLastUpdate = DLookup("LastUpdate", "tblLastUpdate", "DateID = 1")
dateNewUpdate = dateLastUpdate - 1
dateCurrentDate = Date

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = #" & dateCurrentDate & "#" & _
"WHERE (((tblLastUpdate.DateID)=1));"

DoCmd.RunSQL stUpdateLastUpdateSQL


Now the problem is that when this code runs the dateCurrentDate
variable is set correctly at e.g. 08/04/05 and having stepped through
the code this remains correct all the way through, but after the SQL
statement is executed the LastUpdate field is populated with 04/08/05.
This is not simply a case of date formatting on the table as when this
new date is run through the code again the dateNewUpdate variable is
set to 03/08/05.

I have checked all regional settings bith in access and windows and
they all appear to be fine.

Thanks in advance
Matt

Nov 13 '05 #1
5 2913
Matt,

To the best of my knowledge, I believe that SQL always treats dates in the
format mm/dd/yy.

However, I tend to use date serials wherever possible; then convert these
for the users to view - it stops me having to worry about what SQL does to
dates, and the users date / time formatting etc etc

Cheers

John Webb

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #2
It sounds like your default date format is "dd/mm/yyyy". In this case, you
need to format your date to the format "mm/dd/yyyy" as explicit date value
enclosed by # must be in the format "mm/dd/yyyy" regardless of your Regional
Settings.

Try

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = " & Format(dateCurrentDate, '\#mm/dd/yyyy\#') & _
"WHERE (((tblLastUpdate.DateID)=1));"

BTW, if tblLastUpdate is a one-Record Table, then you don't need the 3rd
argument in the DLookUp() and the WHERE clause above is unnecessary.

Not sure of the second part of your second last paragraph but try the above
and see how it comes out.

--
Van T. Dinh

<m_******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Running MS Access 2000
MS Windows XP Pro

This has caused me a lot of hair loss in the last few days so would
appreciate any help.

I am running code to append/update a local access database from a
remote MS SQL database. The method of determining which records to
append is primarily using the last date an update was carried out; I
appreciate that there is probably a better way of doing this but time
contraints prevent me from doing extensive research and dev at the
moment. Below is a section of code from the procedure where
tblLastUpdate is a 2 field single record table used to store the date
the database was last updated.
Dim dateLastUpdate As Date
Dim dateNewUpdate As Date
Dim dateCurrentDate As Date
Dim stUpdateLastUpdateSQL As String
dateLastUpdate = DLookup("LastUpdate", "tblLastUpdate", "DateID = 1")
dateNewUpdate = dateLastUpdate - 1
dateCurrentDate = Date

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = #" & dateCurrentDate & "#" & _
"WHERE (((tblLastUpdate.DateID)=1));"

DoCmd.RunSQL stUpdateLastUpdateSQL


Now the problem is that when this code runs the dateCurrentDate
variable is set correctly at e.g. 08/04/05 and having stepped through
the code this remains correct all the way through, but after the SQL
statement is executed the LastUpdate field is populated with 04/08/05.
This is not simply a case of date formatting on the table as when this
new date is run through the code again the dateNewUpdate variable is
set to 03/08/05.

I have checked all regional settings bith in access and windows and
they all appear to be fine.

Thanks in advance
Matt

Nov 13 '05 #3
Thanks for the suggestions, haven't had chance to try yet but will get
back when I have.

"Van T. Dinh" <Va***********@discussions.microsoft.com> wrote in message news:<8V*****************@news-server.bigpond.net.au>...
It sounds like your default date format is "dd/mm/yyyy". In this case, you
need to format your date to the format "mm/dd/yyyy" as explicit date value
enclosed by # must be in the format "mm/dd/yyyy" regardless of your Regional
Settings.

Try

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = " & Format(dateCurrentDate, '\#mm/dd/yyyy\#') & _
"WHERE (((tblLastUpdate.DateID)=1));"

BTW, if tblLastUpdate is a one-Record Table, then you don't need the 3rd
argument in the DLookUp() and the WHERE clause above is unnecessary.

Not sure of the second part of your second last paragraph but try the above
and see how it comes out.

--
Van T. Dinh

<m_******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Running MS Access 2000
MS Windows XP Pro

This has caused me a lot of hair loss in the last few days so would
appreciate any help.

I am running code to append/update a local access database from a
remote MS SQL database. The method of determining which records to
append is primarily using the last date an update was carried out; I
appreciate that there is probably a better way of doing this but time
contraints prevent me from doing extensive research and dev at the
moment. Below is a section of code from the procedure where
tblLastUpdate is a 2 field single record table used to store the date
the database was last updated.
>

Dim dateLastUpdate As Date
Dim dateNewUpdate As Date
Dim dateCurrentDate As Date
Dim stUpdateLastUpdateSQL As String
dateLastUpdate = DLookup("LastUpdate", "tblLastUpdate", "DateID = 1")
dateNewUpdate = dateLastUpdate - 1
dateCurrentDate = Date

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = #" & dateCurrentDate & "#" & _
"WHERE (((tblLastUpdate.DateID)=1));"

DoCmd.RunSQL stUpdateLastUpdateSQL
>


Now the problem is that when this code runs the dateCurrentDate
variable is set correctly at e.g. 08/04/05 and having stepped through
the code this remains correct all the way through, but after the SQL
statement is executed the LastUpdate field is populated with 04/08/05.
This is not simply a case of date formatting on the table as when this
new date is run through the code again the dateNewUpdate variable is
set to 03/08/05.

I have checked all regional settings bith in access and windows and
they all appear to be fine.

Thanks in advance
Matt

Nov 13 '05 #4
m_******@hotmail.com (Matt) wrote in message news:<dd**************************@posting.google. com>...

I chickened out and have resorted to using the DoCmd.OpenQuery
Statement elliminating the use of SQL for the time being. So now have
a query to update the LastUpdate in tblLastUpdate to todays date and,
to limit the records retrieved, the date dependant query has the
criteria: >=((DLookUp("[LastUpdate]","tblLastUpdate","[DateID]=1"))-1).
This seems to do the trick. All suggestions very much appreciated and
I will certainly be making use of them in the future when I make
improvements in the future.

Thanks again,
Matt
Thanks for the suggestions, haven't had chance to try yet but will get
back when I have.

"Van T. Dinh" <Va***********@discussions.microsoft.com> wrote in message news:<8V*****************@news-server.bigpond.net.au>...
It sounds like your default date format is "dd/mm/yyyy". In this case, you
need to format your date to the format "mm/dd/yyyy" as explicit date value
enclosed by # must be in the format "mm/dd/yyyy" regardless of your Regional
Settings.

Try

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = " & Format(dateCurrentDate, '\#mm/dd/yyyy\#') & _
"WHERE (((tblLastUpdate.DateID)=1));"

BTW, if tblLastUpdate is a one-Record Table, then you don't need the 3rd
argument in the DLookUp() and the WHERE clause above is unnecessary.

Not sure of the second part of your second last paragraph but try the above
and see how it comes out.

--
Van T. Dinh

<m_******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Running MS Access 2000
MS Windows XP Pro

This has caused me a lot of hair loss in the last few days so would
appreciate any help.

I am running code to append/update a local access database from a
remote MS SQL database. The method of determining which records to
append is primarily using the last date an update was carried out; I
appreciate that there is probably a better way of doing this but time
contraints prevent me from doing extensive research and dev at the
moment. Below is a section of code from the procedure where
tblLastUpdate is a 2 field single record table used to store the date
the database was last updated.

>>
Dim dateLastUpdate As Date
Dim dateNewUpdate As Date
Dim dateCurrentDate As Date
Dim stUpdateLastUpdateSQL As String
dateLastUpdate = DLookup("LastUpdate", "tblLastUpdate", "DateID = 1")
dateNewUpdate = dateLastUpdate - 1
dateCurrentDate = Date

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = #" & dateCurrentDate & "#" & _
"WHERE (((tblLastUpdate.DateID)=1));"

DoCmd.RunSQL stUpdateLastUpdateSQL
>>

Now the problem is that when this code runs the dateCurrentDate
variable is set correctly at e.g. 08/04/05 and having stepped through
the code this remains correct all the way through, but after the SQL
statement is executed the LastUpdate field is populated with 04/08/05.
This is not simply a case of date formatting on the table as when this
new date is run through the code again the dateNewUpdate variable is
set to 03/08/05.

I have checked all regional settings bith in access and windows and
they all appear to be fine.

Thanks in advance
Matt

Nov 13 '05 #5
I found some time last night and had a go with the suggestion and it
worked, my SQL string now looks like this.

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = #" & Format(CDate(Date), "mm-dd-yyyy") &
"#" & "WHERE (((tblLastUpdate.DateID)=1));"

And the LastUpdate field in tblLastUpdate is now populated in the
correct format. Many thanks again

Matt

m_******@hotmail.com (Matt) wrote in message news:<dd**************************@posting.google. com>...
m_******@hotmail.com (Matt) wrote in message news:<dd**************************@posting.google. com>...

I chickened out and have resorted to using the DoCmd.OpenQuery
Statement elliminating the use of SQL for the time being. So now have
a query to update the LastUpdate in tblLastUpdate to todays date and,
to limit the records retrieved, the date dependant query has the
criteria: >=((DLookUp("[LastUpdate]","tblLastUpdate","[DateID]=1"))-1).
This seems to do the trick. All suggestions very much appreciated and
I will certainly be making use of them in the future when I make
improvements in the future.

Thanks again,
Matt
Thanks for the suggestions, haven't had chance to try yet but will get
back when I have.

"Van T. Dinh" <Va***********@discussions.microsoft.com> wrote in message news:<8V*****************@news-server.bigpond.net.au>...
It sounds like your default date format is "dd/mm/yyyy". In this case, you
need to format your date to the format "mm/dd/yyyy" as explicit date value
enclosed by # must be in the format "mm/dd/yyyy" regardless of your Regional
Settings.

Try

stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
tblLastUpdate.LastUpdate = " & Format(dateCurrentDate, '\#mm/dd/yyyy\#') & _
"WHERE (((tblLastUpdate.DateID)=1));"

BTW, if tblLastUpdate is a one-Record Table, then you don't need the 3rd
argument in the DLookUp() and the WHERE clause above is unnecessary.

Not sure of the second part of your second last paragraph but try the above
and see how it comes out.

--
Van T. Dinh

<m_******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
> Running MS Access 2000
> MS Windows XP Pro
>
> This has caused me a lot of hair loss in the last few days so would
> appreciate any help.
>
> I am running code to append/update a local access database from a
> remote MS SQL database. The method of determining which records to
> append is primarily using the last date an update was carried out; I
> appreciate that there is probably a better way of doing this but time
> contraints prevent me from doing extensive research and dev at the
> moment. Below is a section of code from the procedure where
> tblLastUpdate is a 2 field single record table used to store the date
> the database was last updated.
>
> >>
> Dim dateLastUpdate As Date
> Dim dateNewUpdate As Date
> Dim dateCurrentDate As Date
> Dim stUpdateLastUpdateSQL As String
>
>
> dateLastUpdate = DLookup("LastUpdate", "tblLastUpdate", "DateID = 1")
> dateNewUpdate = dateLastUpdate - 1
> dateCurrentDate = Date
>
> stUpdateLastUpdateSQL = "UPDATE tblLastUpdate SET
> tblLastUpdate.LastUpdate = #" & dateCurrentDate & "#" & _
> "WHERE (((tblLastUpdate.DateID)=1));"
>
> DoCmd.RunSQL stUpdateLastUpdateSQL
> >>
>
> Now the problem is that when this code runs the dateCurrentDate
> variable is set correctly at e.g. 08/04/05 and having stepped through
> the code this remains correct all the way through, but after the SQL
> statement is executed the LastUpdate field is populated with 04/08/05.
> This is not simply a case of date formatting on the table as when this
> new date is run through the code again the dateNewUpdate variable is
> set to 03/08/05.
>
> I have checked all regional settings bith in access and windows and
> they all appear to be fine.
>
> Thanks in advance
> Matt
>

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.