Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorrect Date in VBA 1

Status
Not open for further replies.

mtnsurfer22

Programmer
Apr 13, 2002
19
0
0
US
I have a table in Access that records the backup status of various servers. The table is updated daily. I want to create a summary form that will show the past 7 days as column headings and each server as row headings. The status (successful/unsuccessful) will then be displayed in the data of the chart. I have created this table manually using label boxes. (This seemed a bit tedious but I could not figure another way to do it, I only have 6 machines so it is only a 6 X 7 table). I was going to use VBA (using a variable array) to fill in the data of the table as captions to my labels. My problem is that I am setting the caption of the column headings using...

Private Sub Form_Load()

Me("lblDate6").Caption = Date - 6
Me("lblDate5").Caption = Date - 5
Me("lblDate4").Caption = Date - 4
Me("lblDate3").Caption = Date - 3
Me("lblDate2").Caption = Date - 2
Me("lblDate1").Caption = Date - 1
Me("lblDate").Caption = Date

End Sub

This was working fine when I first created it...now however, (a few weeks later) the date is still returning the old date. The calculations work fine, but it seems to think that "Date" is 4/11/2004, instead of my current system time.

The Date() statement still works fine in Queries. Also, if I create a new blank database, the Date statement works correctly. Yet, I cannot get the VBA code in my current database to realize that it is not still 4/11/2004.

What am I missing here?

Thanks
 
And what about something like this ?
Me("lblDate6").Caption = [highlight]VBA.[/highlight]Date - 6


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Bingo!! Works great. I also found that the Now() statement works correctly. I have used the Date statement in the past and have not had to use the VBA prefix. Do you know why it was behaving this way for me? Could I be missing a reference?

Thanks again.
 
Don't you have some field or control named Date ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I usually label my controls and fields with prefixes (ie. lbl,txt,cmd) so I didn't even think of that. But I see what you are getting at. I will go back and check. I have a number of subforms and tabs on this form so I'll bet your suspicion is correct.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top