Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 1st, 2005, 11:58 AM
EUCPRLEU EUCPRLEU is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 3 EUCPRLEU User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 46 sec
Reputation Power: 0
Exclamation SQL does not update expected records

I have a table of dates which I wish to update to show the fiscal year and month. I have another table which is the recordset RS here which contains Fiscal Year, Fiscal Month, Start date and End date.

The query should update the correct value based on the SQL below. It seems to be updating the wrong records. Any idea's? I have tried to ensure all data types are setup the same. I know the SQL statement alone selects the wrong records but I can't work out why.

Option Compare Database
Function updateDates()
Dim db As Database
Dim rs As Recordset
DoCmd.SetWarnings False
DoCmd.Hourglass True
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblUpdates", 2, 2, 2)
Do While Not rs.EOF
DoCmd.RunSQL "UPDATE VPRECLOG SET VPRECLOG.FY_YR = '" & rs![upFiscalYear] & "', VPRECLOG.FY_MONTH = '" & rs![upFiscalMonth] & "' WHERE (((VPRECLOG.DateCorrected) Between #" & Format(rs![upStartDate], "dd/mm/yyyy") & "# And #" & Format(rs![upEndDate], "dd/mm/yyyy") & "#));"
rs.MoveNext
Loop
rs.Close
db.Close
DoCmd.SetWarnings True
DoCmd.Hourglass False
End Function

Reply With Quote
  #2  
Old February 1st, 2005, 12:13 PM
EUCPRLEU EUCPRLEU is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 3 EUCPRLEU User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 46 sec
Reputation Power: 0
Even this doesn't work???

SELECT VPRECLOG.FY_YR, VPRECLOG.FY_MONTH
FROM VPRECLOG
WHERE (((VPRECLOG.DateCorrected) Between #1/1/2004# And #2/1/2004#));

Reply With Quote
  #3  
Old February 2nd, 2005, 10:16 AM
mark_bell mark_bell is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 mark_bell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 52 sec
Reputation Power: 0
SELECT VPRECLOG.FY_YR, VPRECLOG.FY_MONTH
FROM VPRECLOG
WHERE (((VPRECLOG.DateCorrected) Between #1/1/2004# And #2/1/2004#));I assume from the above you are trying to select dates 1-Jan-2004 to 2-Jan-2004.

If this is the case then the error is with your date formats. When you SQL statements with dates between ## you need to use the standard American format mm/dd/yyyy and not the UK dd/mm/yyyy.

You can run a query with either date format

Reply With Quote
  #4  
Old February 3rd, 2005, 04:03 AM
EUCPRLEU EUCPRLEU is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 3 EUCPRLEU User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 46 sec
Reputation Power: 0
I assume from the above you are trying to select dates 1-Jan-2004 to 2-Jan-2004.

If this is the case then the error is with your date formats. When you SQL statements with dates between ## you need to use the standard American format mm/dd/yyyy and not the UK dd/mm/yyyy.

[Iain] - Hi Mark. Firstly thanks for your response. You are right it interprets all dates as US format, not obvious when the date formats for the field are set to UK. Also when passing a value from a user form I know from passed experience Access handles it in the format it is enetered. The solution to make my code work correctly is to convert the UK date to a US date before passing into the SQL statement.

Between #" & Format(rs![upStartDate], "mm/dd/yyyy") & "# And #" & Format(rs![upEndDate], "mm/dd/yyyy") & "#))

Again thanks for your help.

Iain

Function updateDates()
Dim db As Database
Dim rs As Recordset
DoCmd.SetWarnings False
DoCmd.Hourglass True
DoCmd.OpenQuery "SetDatesNull", acViewNormal
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblUpdates", 2, 2, 2)
Do While Not rs.EOF
DoCmd.RunSQL "UPDATE tblReceiptLog SET tblReceiptLog.FY_YR = '" & rs![upFiscalYear] & "', tblReceiptLog.FY_MONTH = '" & rs![upFiscalMonth] & "' WHERE (((tblReceiptLog.DateCorrected) Between #" & Format(rs![upStartDate], "mm/dd/yyyy") & "# And #" & Format(rs![upEndDate], "mm/dd/yyyy") & "#));"
rs.MoveNext
Loop
rs.Close
db.Close
DoCmd.SetWarnings True
DoCmd.Hourglass False
End Function

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > SQL does not update expected records


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT