screenwriter776 (AT) hotmail (DOT) com (screenwriter776) wrote in message news:<2faa126e.0404190947.73f80fb2 (AT) posting (DOT) google.com>...
Quote:
Hi, folks -
I'm trying to default one of my table fields to Now(), rounded to the
nearest hour. If I enter a new record at 4/19 10:29 am, I'd like the
field to store 4/19 10:00 am. If I enter a record at 4/19 10:31 am,
I'd like the field to store 4/19 11:00 am, etc.
Can't seem to find any basic "round" functions to attach to now() and
achieve this result in the "default value" of my field.
Any advice would be VERY appreciated!
Thanks,
sw776 |
Hello SW776,
A question I have is, are you inputting your data from the datasheet
view of your table? If so, perhaps you should set up a form for
inputting. Just checking.
If you are using a form, one thing you can do is add another column
to the Record Source query like the following:
TimeRounded: rndTime([txtAutoDateField])
Add your date text field into the function above and
replace "txtAutoDateField".
This sources the following function located in a module.
----
Function rndTime(x As Variant) As Variant
Dim getRndTime As Date
Dim sMinutes As String, sHours As String
sMinutes = DatePart("n", x)
sHours = DatePart("h", x)
Select Case sMinutes
Case 0 To 29.59
rndTime = Format(x, "d" & "/" & "m" & " " & sHours & ":00:00")
Case 30 To 59
rndTime = Format(x, "d" & "/" & "m" & " " & sHours + 1 & ":00:00")
End Select
End Function
----
Perhaps you can name the module "mod01RoundTime".
Then, run the query. You can use the field according to your
needs. From the form, have the new formated date saved into
a field from an "After Update" property of a field that receives
data input for every record as an example.
Regards,
Ray