Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 3rd, 2005, 08:07 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble with date formats

Here's one people in the States might not have encountered, but it's a curly one for me!

I have a two combo boxes in a form where the user selects a start and end date for a record search. My code retrieves these values, creates an SQL string and changes the underlying QueryDef. The dates are of course dd/mm/yyyy format (Australia).

    If chkDate Then
        dateStart = cmbStartDate.Value
        dateEnd = cmbEndDate.Value
        strSQL = strSQL & " tblLog.[Log Date] Between #" & dateStart & "# And #" & dateEnd & "#"
    End If

My problem is this: when the SQL string is sent to the QueryDef, Access attempts to change the date format to mm/dd/yyyy. This is fine for unambiguous dates, such as 18/2/2005, but where the day is less than 12, it invariably ends up reversed, even if I convert all of my dates to mm/dd/yyyy first. Does anyone have any suggestions?

Drew
  #2 (permalink)  
Old March 4th, 2005, 10:13 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am not sure why you need to force the ## date issue in the SQL string. Try this for grins:

'==========
strSQL = strSQL & " tblLog.[Log Date] Between " & "'" & dateStart & "'" & " And " & "'" & dateEnd & "'"
'==========

Access should just take the value without forcing the date issue.

HTH
:D

mmcdonal
  #3 (permalink)  
Old March 6th, 2005, 07:01 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm, well I just end up with a run-time error saying I cancelled the previous operation. This relates to a "data type mismatch" in the criteria of the query. Doesn't seem to like the 'dd/mm/yyyy' format. I tried enabling ANSI92 syntax, but it didn't help. looks like I might just have to rearrange the dates using string handlers:-(
  #4 (permalink)  
Old March 7th, 2005, 06:22 PM
Authorized User
 
Join Date: Jul 2004
Location: clapton-in-gordano, n.somerset, United Kingdom.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Good Ole US Dates. Don't you just love them!

 Try using
strSQL = strSQL & " tblLog.[Log Date] Between #" & Format(dateStart,"mm/dd/yy") & "# And #" & Format(dateEnd,"mm/dd/yy") & "#"

Unless you are using an SQL Server, this usually works, but only if dateStart and dateEnd are Dim'd as dates.

Good luck

ElanSolutionsLtd



Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Formats carumuga SQL Server 2000 4 January 2nd, 2007 07:20 PM
XML Date Formats tracyamgray XSLT 5 July 12th, 2006 10:17 PM
displaying different date formats using LCID leo_vinay Classic ASP Basics 1 November 26th, 2004 07:17 PM
SQL and Date Formats al_bllinky Access 3 August 28th, 2003 08:45 AM
Date formats in the forum Crispin Horsfield Forum and Wrox.com Feedback 1 August 3rd, 2003 08:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.