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

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 3143
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*******@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.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********@hotmail.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.txtFromDate); " to ";
CLng(Me.txtToDate)
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.txtFromDate.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.FromDate = CVDate(Me.txtFromDate.Value)
r_reportdata.ToDate = CVDate(Me.txtToDate.Value)
lstrTemp = "GL run from " & Format(r_reportdata.FromDate, "short date")
& " to " & Format(r_reportdata.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.txtFromDate); " to ";
CLng(Me.txtToDate)
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.txtFromDate.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
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,...
8
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. ...
6
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...
2
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...
2
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....
22
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...
4
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...
9
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...
9
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...
0
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...

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.