473,385 Members | 1,615 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,385 software developers and data experts.

date problem between vba and query grid

I have a vba string taht dynamically creates the query which has two dates
in it that it grabs off an open form as a string from the textbox.

What I generate in vba is:

SELECT DOSMBK.Date, DOSMBK.[DOSM-DSName] FROM DOSMBK WHERE
(((DOSMBK.Date)<#19/04/2004#) AND ((DOSMBK.[DOSM-DSName])="M9S" Or
(DOSMBK.[DOSM-DSName])="M9SA") AND ((DOSMBK.From)=#06/09/2004#));

If I view this as the sql view after opening the query grid I get this:

SELECT DOSMBK.Date, DOSMBK.[DOSM-DSName]
FROM DOSMBK
WHERE (((DOSMBK.Date)<#4/19/2004#) AND ((DOSMBK.[DOSM-DSName])="M9S" Or
(DOSMBK.[DOSM-DSName])="M9SA") AND ((DOSMBK.From)=#6/9/2004#));
it has changed the date to an american style ie #4/19/2004#
Any ideas why? I guess I have done something stupid here.

If I view the query grid in design view the criteria shows <#19/04/2004#

which is how it should be.

Regards in advance
Peter
Nov 13 '05 #1
4 6300
Access VBA uses american date format mm/dd/yyyy
Nov 13 '05 #2
Hi Pieter

because I am sending only a string and creating the query from that I
thought I might get around that problem as the data type for the date is a
string and not a date.

:(

"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf*************************@posting.google.co m...
Access VBA uses american date format mm/dd/yyyy

Nov 13 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You've used American date format delimiters (#) in your query, which
indicates, to me, that the date value is stored as a DateTime data type.
The DateTime data type is a floating point number with the integer part
representing the number of days since December 31, 1899, and the decimal
part representing the number of milliseconds from the date's midnight.

When you're creating the SQL string use the CDate() function on your
Euro-date formatted date string. E.g.:

CDate("19/4/2004")

I believe it will convert it to a correct date number (April 19, 2004)
'cuz VBA will use your PC's time/date settings to "understand" the
19/4/2004 date string.

Another thing you can do is use PARAMETERS. E.g.:

PARAMETERS StartDate Date, EndDate Date;
SELECT [Date], [DOSM-DSName]
FROM DOSMBK
WHERE DOSMBK.[Date] < StartDate
AND ([DOSM-DSName]="M9S" Or [DOSM-DSName]="M9SA")
AND [From] = EndDate

If you're running the query from the db window, you will be prompted for
the StartDate and EndDate. Enter the dates in your area's date format.
The date value will be converted to the correct number value.

From VBA use the DAO.QueryDef object to set the parameters. E.g.:

dim db as dao.database
dim qd as dao.querydef
set db = currentdb
set qd = db.querydefs("query_name)
qd!StartDate = CDate("19/4/2004")
qd!EndDate = CDate("6/9/2004")
qd.Close ' or do something w/ the QueryDef

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQUnbyoechKqOuFEgEQKoaACfaPUk0Vf9Nz3x1joA4KJj5f lU9mQAniFb
cruYZPRYA8vCGmXA3GtSbGNM
=+ZF+
-----END PGP SIGNATURE-----
Peter Bailey wrote:
I have a vba string taht dynamically creates the query which has two dates
in it that it grabs off an open form as a string from the textbox.

What I generate in vba is:

SELECT DOSMBK.Date, DOSMBK.[DOSM-DSName] FROM DOSMBK WHERE
(((DOSMBK.Date)<#19/04/2004#) AND ((DOSMBK.[DOSM-DSName])="M9S" Or
(DOSMBK.[DOSM-DSName])="M9SA") AND ((DOSMBK.From)=#06/09/2004#));

If I view this as the sql view after opening the query grid I get this:

SELECT DOSMBK.Date, DOSMBK.[DOSM-DSName]
FROM DOSMBK
WHERE (((DOSMBK.Date)<#4/19/2004#) AND ((DOSMBK.[DOSM-DSName])="M9S" Or
(DOSMBK.[DOSM-DSName])="M9SA") AND ((DOSMBK.From)=#6/9/2004#));
it has changed the date to an american style ie #4/19/2004#
Any ideas why? I guess I have done something stupid here.

If I view the query grid in design view the criteria shows <#19/04/2004#

which is how it should be.


Nov 13 '05 #4
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote:
it has changed the date to an american style ie #4/19/2004#
Any ideas why? I guess I have done something stupid here.


Return Dates in US #mm/dd/yyyy# format
http://www.mvps.org/access/datetime/date0005.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 13 '05 #5

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

Similar topics

17
by: Lapchien | last post by:
My table has a record called date/time - filled (not surprisingly) with a date and time. I can format the date in one query field, also the time, using format in an expression. My user wants me...
1
by: Dalan | last post by:
I have attempted to resolve a problem regarding erroneous output using a Between And parameter on several Access 97 queries, but to no avail. The queries are used for report output and...
4
by: Kissi5559 | last post by:
Hello, Could anyone help me with a query? I have a date field and want to display only records for a specified month. Example: Date:5/12/2004 Query for all records in the month of May, 2004. ...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
3
by: Melissa | last post by:
I have this table: TblProjectYear ProjectYearID ProjectYearStartDate ProjectYearEndDate The Project Year will always span across December 31; for example 9/1/04 to 6/30/05. How do I build a...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
4
by: Colin Mardell | last post by:
I have a table with two fields, 'StartDate' and 'EndDate'. How do I get the query to select a record that matches a given date that is between the two dates?
9
by: Rizwan Karedoa | last post by:
Hi experts, I am developing an application, I am using vb 2005 and access. I have many date fields, When I am saving through Query for default date I save 1/1/1500 so when i find that date agian I...
2
by: LLLiddle | last post by:
As an Access learner, I'm tearing my hair out over what is probably a simple problem. I hope someone can help. I have a table for Clients (tbl.Clients with pkClientID). Each client may use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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.