DMax + 1 hour

todgers

Registered User.
Local time
Today, 18:57
Joined
Mar 28, 2006
Messages
42
Hiya
I've searched the forum and can't quite find what I need so I'm asking for further guidance form all you Access masters out there!

I have a field 'Time' in the format of 'dd/mm/yyyy hh:mm' which has a default value of =DMax("Time ","[Monitoring]")+1.

This increments 1 on the 'dd' bit when each new record is created, however what I want is for the hour (hh) bit to increment 1 on each new record.

Not sure if I'm being niave but I thought it was some sort of formatting issue, so I've dabbled with a few but to little effect unfortunately.

Any suggestions?
 
Understand how dates are stored and you'll understand why it adds a day. Use the DateAdd function.
 
Thanks for that

OK I've made the default value DateAdd("h",+1,"Time") with 'Time' being the name of the field and the field having a format of dd/mm/yyyy hh:nn

When I add a new record I get #Error where I am going wrong
 
For one thing, I assume you'd still want to get the max before adding an hour. You probably want the DMax to be the third argument. For another "Time" is a built in function and should not be used as a field name. Access may be confused about whether you want the field or the function. Third, the last argument is not supposed to be a string expression (lose the quotes).
 
Right then, I've renamed my field 'tbotime' and I've put DMax as the third argument. Unfortunately whenever I take the quotes off as soon as I move to the next line, Access has added the quotes back in, if I lose the quotes and use some sort of bracker set up I get various errors.
Thanks for you help so far!
 
Not sure. This works in a test as the default value on a form textbox:

=DateAdd("h",1,DMax("FieldName","TableName"))

Hopefully you realized that I meant that the third argument of the DateAdd function should not have the quotes. Since you've replaced that with the DMax anyway, the point is moot.
 
Superb, it works a treat.

Thanks for all your help, thats a pint I owe you!
 

Users who are viewing this thread

Back
Top Bottom