Date() problems

G

Guest

I am putting together a very simple application and need to identify when the
application is opened in a new month. So I'm using the Month Function to
compare the system date to the last month an entry was made. I built the
tables and form on my work computer and transported the app to my home
computer to do the code. Both computers use XP operating system. The
following code in the Open event of the form gave me a month function return
of "1" on Feb 22, 2007, so I made a text box display the system date and it
displayed 1/1/2007.

Dim intMonth As Integer 'Month function for last recorded date
Dim intDate As Integer 'Month function for today's date
Dim datToday As Date

'Restore
DoCmd.Restore
'Preset fraCycle
Me.fraCycle = 0

'Is this a new month?
datToday = Date
intMonth = Month(datToday)
Me.Text106 = intMonth
Me.Text108 = Date


I checked my system date in the lower right hand corner of my monitor screen
and it was Feb 22, 2007. Then I build a new form with a couple text boxes in
it and the code worked fine.

What code would allow me to transfer this application from XP system to XP
system?
 
D

Douglas J. Steele

I don't understand how, on Feb 22, 2007, the code

datToday = Date
intMonth = Month(datToday)
Me.Text106 = intMonth
Me.Text108 = Date

would result in Text106 containing 1 and Text108 containing 1/1/2007.

In order to know when the application is opened in a new month, you need
somewhere to store when the application was last opened. You could write to
a table each time the application is opened, and then query that table to
find the most recent time it was opened, and compare that to today's date,
or you could store the last opened date in an INI file or the registry, or
you could add a property to the database and store it there. The point is,
you have to store the information somewhere.
 
G

Guest

The text boxes that display 1 and 1/1/2007 - what are they formatted to show?
I suspect that one is formatted as a Short Date and is displaying intMonth as
01/01/1900 perhaps.

BW

Douglas J. Steele said:
I don't understand how, on Feb 22, 2007, the code

datToday = Date
intMonth = Month(datToday)
Me.Text106 = intMonth
Me.Text108 = Date

would result in Text106 containing 1 and Text108 containing 1/1/2007.

In order to know when the application is opened in a new month, you need
somewhere to store when the application was last opened. You could write to
a table each time the application is opened, and then query that table to
find the most recent time it was opened, and compare that to today's date,
or you could store the last opened date in an INI file or the registry, or
you could add a property to the database and store it there. The point is,
you have to store the information somewhere.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top