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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic Date 2

Status
Not open for further replies.

Dannybe2

Programmer
Jan 31, 2001
136
GB
I know how to create an automatic date:

In my form, the default date is:

=Date()

The problem is, I want to select a date in a separate field based on the choice made by another field.

When Status = Open - DateField = Blank
When Status = Resolved - DateField = Current Date

I use the following code:

Dim MyDate
MyDate = Date

DateField = MyDate

It looks for a field called Date.

If I use =Now(), It works, but I don't want the time at all.
 
The problem may be caused by your not declaring the "Datatype" for you variable.

You have:

Dim MyDate

If you do not declare the datatype for the variable Access will assign the datatype as a "Variant". This could be causing the problem ... Access could be evaluating "Date" as a Control, String or even something else. You should "always" declare the datatype if you know what it is.

Try changing your code to this:

Dim MyDate As Date
MyDate = Date

DateField = MyDate

HTH
RDH Ricky Hicks
Birmingham, Alabama


 
Hi,

Yes I believe that is the cause of the problem.
However you can also solve it by formating your date like this

dim myDate As Date
myDate = Format(Now(), "dd/mm/yyyy")
DateField= myDate

Hope this helps
Good luck
 
Thanks a lot, both of you. I do have another problem though which I was hoping you'd be able to solve. I have a field which automatically fills in the time for me as follows:

Table Properties for Field tTime:

Default =Time()
Format = hh:nn

The problem is I always get seconds on the end of the time and I don't want seconds at all. If I change the properties for the box on the form though, then it removes the seconds until you try and edit the time then it adds them again. Why does it do this?

Secondly how do I round the time up to the nearest five minutes, so I get 15:40, 15:45, 15:50, etc. ?

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top