473,788 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6327
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********@hot mail.com> wrote in message
news:bf******** *************** **@posting.goog le.com...
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("q uery_name)
qd!StartDate = CDate("19/4/2004")
qd!EndDate = CDate("6/9/2004")
qd.Close ' or do something w/ the QueryDef

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

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

iQA/AwUBQUnbyoechKq OuFEgEQKoaACfaP Uk0Vf9Nz3x1joA4 KJj5flU9mQAniFb
cruYZPRYA8vCGmX A3GtSbGNM
=+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*********@an daluz.fsbusines s.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
25903
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 to provide a listing of all table entries between 22:00 and 07:30 the next day, between a given set of dates (typically one week apart but in practice between any dates specified). My query works ok for 1 date - entering 2 dates, one for 22:00 -...
1
2237
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 regardless of the beginning and ending dates entered, the reports show all activity including before and after the dates entered. There is a frmAccount and two subforms sfrmPurchase and sfrm Sales. In order to isolate costs for each collectively, both...
4
2319
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. Thanks.
7
2463
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 filled (with Now()) and the purchase date is entered manually. Meantime I became aware that instead of Now() I should use Date() for the date
3
6624
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 combobox based on this table that will display all the months between the StartDate and the EndDate for a given ProjectYearID and when a selection is made, the full date of the last day of the selected
12
6392
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 ranges, ie between 24/09/2004 and 01/10/2004 together with 05/10/2004 and 07/10/2004 ? If I enter the "Between" criteria on different lines it returns no data.
4
2201
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
3976
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 know its a blank date. Now The problem is when i attach Dataset to a datagridview, grid will show date 1/1/1500, I don't want to show that date to user. Is there any way I can have blank date in data grid when it finds 1/1/1500 as date....
2
1403
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 one, two or three services (tblFood, tblMoney, and tblMentoring). Each of these tables contains a field, fkClientID. Within each of the three service tables there is a date field indicating each occasion a client used the service. A client may...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.