Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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
Reply With Quote
  #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
Reply With Quote
  #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:-(
Reply With Quote
  #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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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


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



All times are GMT -4. The time now is 12:07 PM.


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