Wrox Programmer Forums
|
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
 
Old July 9th, 2003, 09:33 AM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to juliya_sh
Default vb and sql

hello,
i need get the field-date in specific format by sql in the vb
i know it something as dateformat but i didn't know
how i do it.
can somebody help ?
thanks
 
Old July 9th, 2003, 09:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by juliya_sh
"SELECT Count(id) AS SumID " & _
     "from [Table] " & _
     "WHERE ( ((" & _
     "[table].[date1]) " & _
     "Between #" + Format(i, "dd/mm/yyyy") + "# And #" + Format (j, "dd/mm/yyyy") + "#) ) "

What exactly are i and j? Also, change the plus signs (+) to ampersands (&). You're concatenating strings, not adding numbers.



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old July 9th, 2003, 06:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think i and j really have to be formatted for this, but, if you insist:

DatePart('d',i) & "/" & DatePart('m',i) & "/" & DatePart('yyyy',i)

likewise with j

And as a note, + can be used to concatenate strings, it's just by convention that most peole use &, which makes it less ambiguous.

+ will still work, and I know some people (well - only one to be honest) who always use + instead of &.

Oh yeah - and I'm assuming that i and j are already dates, not strings. which is why formatting wouldn't be necessary - unless of course i and j were dates with times, and you wanted to roll them both back to midnight.
If i and j are strings, with a format like "mm/dd/yyyy", then you'd have to use left, mid, right and len functions, like:

Mid(Field,4,2)& "/" & Left(Field,2) & "/" & Right(Field,4)

You'd run into a problem if the string didn't necessarily have all the digits filled, for example, 1/1/2001
in which case you'd have to use the InStr function to find the "/" and select the part of the string based on its location

I'm assuming this reply answers most scenarios.

Steven

There are 10 kinds of people in the world - those who understand binary - and those with friends





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with VB SQL Server 7.0 danfeather VB Databases Basics 2 September 23rd, 2005 09:58 AM
Help! At a lose: SQL and VB xgbnow Pro VB Databases 2 June 9th, 2004 10:12 PM
vb and sql juliya_sh Access VBA 1 July 9th, 2003 06:40 PM
ms Project,vb,sql m_ctrl VB How-To 0 June 28th, 2003 10:36 AM
ms project,sql,vb m_ctrl Pro VB 6 0 June 28th, 2003 10:28 AM





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