473,652 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS Access 2000 VBA Code Shows Totally Incorrect Date from Controls on a Form

Hi,

Sorry for my English. English is not my native tougue.

I am working in MS Access 2000 with a SQLServer 2000 Backend database.
MS Access 2000 is my GUI front end that has SQLServer linked tables in
it. One of my forms has two TEXT BOX controls formated as Short Date.
The form is binded to a linked table. The linked tables has about 7
records and one of the control is binded to a table field. These two
controls displays the date correctly as 01/07/2006 and 31/07/2006 (I am
running Windows XP, my regional setting is set to English Australia,
location is set to Australia, language for non-Unicode programs is set
to English Australia, and my date format is set to d/MM/YYYY) when the
form is running. I have some VBA code behind the form to print out
these two dates to a text file. The dates show up as 30/12/2005 and
30/01/2006. I really do not know why these dates are totally different.
Here's my VBA code:

Open "C:\Results.txt " For Output Access Write Lock Write As #1
Print #1, "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
Print #1, ""
::
::
Close #1

I am hoping some one has come across with this problem.

Thanks in advance,

Easystart

Aug 10 '06 #1
5 3160
oh, so you mean you're just outputting everything to a text file?

My guess is that since MS stores all it's data in US format, your have
to force it into Australian format when you write it to the file. What
happens if you use Format() and force it into the format you want?

Aug 10 '06 #2
There are some basic things you need to do to ensure Access interprets our
d/m/y dates correctly.

Specifically:
- Set the Format property of unbound contorls, so Access knows they are
dates.
- Declare parameters in your query, so Access gets the type right.
- Typecast calculated fields, so Access gets the type right.
- Understand the difference between dates entered in the interface, and
dates entered into VBA code or SQL clauses.

Details in:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html

Also:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Easystart" <nh*******@hotm ail.comwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.com...
>
Sorry for my English. English is not my native tougue.

I am working in MS Access 2000 with a SQLServer 2000 Backend database.
MS Access 2000 is my GUI front end that has SQLServer linked tables in
it. One of my forms has two TEXT BOX controls formated as Short Date.
The form is binded to a linked table. The linked tables has about 7
records and one of the control is binded to a table field. These two
controls displays the date correctly as 01/07/2006 and 31/07/2006 (I am
running Windows XP, my regional setting is set to English Australia,
location is set to Australia, language for non-Unicode programs is set
to English Australia, and my date format is set to d/MM/YYYY) when the
form is running. I have some VBA code behind the form to print out
these two dates to a text file. The dates show up as 30/12/2005 and
30/01/2006. I really do not know why these dates are totally different.
Here's my VBA code:

Open "C:\Results.txt " For Output Access Write Lock Write As #1
Print #1, "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
Print #1, ""
::
::
Close #1

I am hoping some one has come across with this problem.

Thanks in advance,

Easystart

Aug 10 '06 #3
pi********@hotm ail.com wrote:
My guess is that since MS stores all it's data in US format
I think store is not the correct word here. Dates are stored in 8
bytes, resembling doubles. MS requires the US format (mm/dd/yyyy) or an
international format (yyyy-mm-dd) to interpret date strings correctly.

Aug 10 '06 #4
Easystart wrote:
Hi,

Sorry for my English. English is not my native tougue.

I am working in MS Access 2000 with a SQLServer 2000 Backend database.
MS Access 2000 is my GUI front end that has SQLServer linked tables in
it. One of my forms has two TEXT BOX controls formated as Short Date.
The form is binded to a linked table. The linked tables has about 7
records and one of the control is binded to a table field. These two
controls displays the date correctly as 01/07/2006 and 31/07/2006 (I am
running Windows XP, my regional setting is set to English Australia,
location is set to Australia, language for non-Unicode programs is set
to English Australia, and my date format is set to d/MM/YYYY) when the
form is running. I have some VBA code behind the form to print out
these two dates to a text file. The dates show up as 30/12/2005 and
30/01/2006. I really do not know why these dates are totally different.
Here's my VBA code:

Open "C:\Results.txt " For Output Access Write Lock Write As #1
Print #1, "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
Print #1, ""
::
::
Close #1

I am hoping some one has come across with this problem.

Thanks in advance,

Easystart
I cannot duplicate your results. It seems that something obvious
(exchanging day and month positions;
allowing for SQL-Server day zero to be two days later than VBA
[1900-01-01 as opposed to 1899-12-30];
the "#" character being interpreted to mean number by the print command
rather that date-number)
isn't jumping out here.

I note that, depending upon rounding, the error dates are one half year
earlier than the correct dates. Are you doing anything with six months,
half a year in this procedure or any procedure connected with this
form?

I suggest that you run

Open "C:\Results.txt " For Output Access Write Lock Write As #1
Debug.Print "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
Debug.Print "GL run from "; Clng(Me.txtFrom Date); " to ";
CLng(Me.txtToDa te)
Print #1, "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
.....

to see if the values appearing in the Immediate Window will shed some
light on what's going wrong. I would also be more explicit as in
Me.txtFromDate. Value.
or
Format(Me.txtFr omDate.Value, "yyyy-mm-dd")

Aug 10 '06 #5
Hi,

It is Easystart again.

After reading your replies, I have made a small change. Here's my
change:

r_reportdata.Fr omDate = CVDate(Me.txtFr omDate.Value)
r_reportdata.To Date = CVDate(Me.txtTo Date.Value)
lstrTemp = "GL run from " & Format(r_report data.FromDate, "short date")
& " to " & Format(r_report data.ToDate, "short date")
::
::
Print #1, lstrTemp

The two controls on my form are already formated as short date.

Let's wait for my Client to try it out and I will post the result.

Regards,

Easystart.


Lyle Fairfield wrote:
Easystart wrote:
Hi,

Sorry for my English. English is not my native tougue.

I am working in MS Access 2000 with a SQLServer 2000 Backend database.
MS Access 2000 is my GUI front end that has SQLServer linked tables in
it. One of my forms has two TEXT BOX controls formated as Short Date.
The form is binded to a linked table. The linked tables has about 7
records and one of the control is binded to a table field. These two
controls displays the date correctly as 01/07/2006 and 31/07/2006 (I am
running Windows XP, my regional setting is set to English Australia,
location is set to Australia, language for non-Unicode programs is set
to English Australia, and my date format is set to d/MM/YYYY) when the
form is running. I have some VBA code behind the form to print out
these two dates to a text file. The dates show up as 30/12/2005 and
30/01/2006. I really do not know why these dates are totally different.
Here's my VBA code:

Open "C:\Results.txt " For Output Access Write Lock Write As #1
Print #1, "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
Print #1, ""
::
::
Close #1

I am hoping some one has come across with this problem.

Thanks in advance,

Easystart

I cannot duplicate your results. It seems that something obvious
(exchanging day and month positions;
allowing for SQL-Server day zero to be two days later than VBA
[1900-01-01 as opposed to 1899-12-30];
the "#" character being interpreted to mean number by the print command
rather that date-number)
isn't jumping out here.

I note that, depending upon rounding, the error dates are one half year
earlier than the correct dates. Are you doing anything with six months,
half a year in this procedure or any procedure connected with this
form?

I suggest that you run

Open "C:\Results.txt " For Output Access Write Lock Write As #1
Debug.Print "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
Debug.Print "GL run from "; Clng(Me.txtFrom Date); " to ";
CLng(Me.txtToDa te)
Print #1, "GL run from "; Me.txtFromDate; " to "; Me.txtToDate
....

to see if the values appearing in the Immediate Window will shed some
light on what's going wrong. I would also be more explicit as in
Me.txtFromDate. Value.
or
Format(Me.txtFr omDate.Value, "yyyy-mm-dd")
Aug 14 '06 #6

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

Similar topics

3
34907
by: Leader | last post by:
Hi All, I am facing a problem with a sql what i used in MS Access but its not returning the same result in MS Sql Server 2000. Here i am giving the sql: SELECT TOP 3 format( MY_DATE, "dddd mm, yyyy" ) FROM MY_TAB WHERE MY_ID=1 The above sql in ACCESS return me the date in below format in one column:
8
2069
by: William Bradley | last post by:
First of all I have been working with Access 97 and this morning the owner of the business phoned me to inform me that he had updated to Access 2000 and parts of my forms would not work anymore. On my form I have a field "Expiry Date".When I put the following into the AfterUpdate field, it adds 183 days to the current date, and displays it in the "Expiry Date" field. Me.ExpDate = DateAdd("d", 183, Me.Date)
6
4739
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
2
352
by: Dave PNNZ | last post by:
Can someone help! I want to insert a feild on a Access 2000 database form where you insert Date of Birth in another feild I want in to automaticly caculate how old the person is in years can someone tell me how to do this. cheers Dave
2
2029
by: David C. Barber | last post by:
upsized an MDB to ADP/SQL Server 2000 under Access 2000. All the DAO code that I've changed to ADO code is working fine, HOWEVER the form Record Source itself does not seem willing to return data. I've set the Record Source to both the query, and the SQL contained within the query, and although the system pauses long enough to have gone out and retrieved the data, I can't see it. The form itself remains gray. In addition: ...
22
6255
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need to be able to speak intelligently about when one client (MS Access vs ..NET Windows Forms) would be preferred over the other. While I have some good arguments on both sides, I would appreciate your points of view on the topic.
4
3092
by: tt40 | last post by:
Anyone know how to prevent Access 2002 from automatically breaking all the incorrect joins in a query and then automatically saving the broken query? This is what I would call stupid design behaviour...Access takes your 'broken' query and auto saves it as what I call a 'corrupt' query... 1. Rename some BE tables and attributes 2. Open your FE 3. Open a query in design view that you know to now have broken names
9
1976
by: Ron | last post by:
Hi All, I've recently installed a program written in Access 2000 on a laptop. The laptop had an existing Office 2000 Pro which of course included Access. But the program acts oddly (more oddly than I would have programmed, anyway). On everyday controls, everything acts normally. But on some controls (and they're always the same ones) the operator can't add or change data. Take a birthday field as an example. If the client was born...
9
4485
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd like to know is the stability, speed & ease of use of both the products. I believe Access 2007 has a new file format too and that it may be slower.
0
8370
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
8283
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,...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
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
5620
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
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.