Increment a Short Time Field by 15 minutes

C

croy

On a data-entry subform, it would be helpful to set the
default for a time field to be 15 minutes more than the last
entry.

I've tried to put code on the AfterUpdate event of the
txtCntTime field like this:

dMax([CntTime],tblUseCountDetails,[UCDId]=me.txtUCDId)

.... but just get "0:00" in the textbox.

I also tried a variant of that in the default property for
txtCntTime, but just got "#Name?" in the textbox.

Any thoughts?
 
J

John W. Vinson

On a data-entry subform, it would be helpful to set the
default for a time field to be 15 minutes more than the last
entry.

I've tried to put code on the AfterUpdate event of the
txtCntTime field like this:

dMax([CntTime],tblUseCountDetails,[UCDId]=me.txtUCDId)

... but just get "0:00" in the textbox.

I also tried a variant of that in the default property for
txtCntTime, but just got "#Name?" in the textbox.

Any thoughts?

The arguments to DMax() (and all the domain functions) must be text strings:
the first the name of a field, the second the name of the Table or Query
containing that field, and the (optional) third argument a valid SQL WHERE
clause (without the WHERE keyword) specifying which record in the table/query.

However, your dMax expression does not do what your intro specifies. If you
really want to set the default value to 15 minutes after the maximum CntTime,
you could use:

Private Sub txtCntTime_AfterUpdate()
If Not IsNull(Me!txtCntTime) Then ' only set default if a value exists
Me!txtCntTime.DefaultValue = Chr(34) & _
Format(DateAdd("n", 15, Me!txtCntTime), "hh:nn") & Chr(34))
End If
End Sub

This assumes that CntTime is a pure time value such as 10:35; if it's a date
and time value, use a Format of "yyyy-mm-dd hh:nn".

Note the suggestions in my .sig - this forum was killed off by Microsoft
several years ago, and exists only in the dark underworld of Usenet Zombie
Newsgroups. This is the first post I've seen here in some months.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:

http://answers.microsoft.com/en-us/office/forum/access?tab=question&status=all
http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=accessdev
and see also http://www.utteraccess.com
 
C

croy

On a data-entry subform, it would be helpful to set the
default for a time field to be 15 minutes more than the last
entry.

I've tried to put code on the AfterUpdate event of the
txtCntTime field like this:

dMax([CntTime],tblUseCountDetails,[UCDId]=me.txtUCDId)

... but just get "0:00" in the textbox.

I also tried a variant of that in the default property for
txtCntTime, but just got "#Name?" in the textbox.

Any thoughts?

The arguments to DMax() (and all the domain functions) must be text strings:
the first the name of a field, the second the name of the Table or Query
containing that field, and the (optional) third argument a valid SQL WHERE
clause (without the WHERE keyword) specifying which record in the table/query.

However, your dMax expression does not do what your intro specifies. If you
really want to set the default value to 15 minutes after the maximum CntTime,
you could use:

Private Sub txtCntTime_AfterUpdate()
If Not IsNull(Me!txtCntTime) Then ' only set default if a value exists
Me!txtCntTime.DefaultValue = Chr(34) & _
Format(DateAdd("n", 15, Me!txtCntTime), "hh:nn") & Chr(34))
End If
End Sub

This assumes that CntTime is a pure time value such as 10:35; if it's a date
and time value, use a Format of "yyyy-mm-dd hh:nn".

Note the suggestions in my .sig - this forum was killed off by Microsoft
several years ago, and exists only in the dark underworld of Usenet Zombie
Newsgroups. This is the first post I've seen here in some months.

Very nice! Thank you for your response. Works like a
charm.
 

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