Hi John and Marshall,
thank you both for your good advices.
Me too would prefer the solution [mytime=#08:30#], but since I will get the
time values from action on a form (John, it is a really good point to use an
option group for this, thanks), it would mean having to go with
[mytime=CDate("#" & value & "#")], as Marshall suggested, which may well look
clearer, but involve using a function to get the job done. And CDate is
really sensible to the user regional settings.
Plus it sounds awkward to me having to build a string and then convert it
into a date/time values.
I will give a shoot at solution (b). It use a little math but looks like I'm
assigning the value in one row only, instead on relying on another function
which rely on user pc general settings.
But I may well be wrong. I'm 99% of time, so...
Thank you both!
roccop
"Marshall Barton" wrote:
> rocco wrote:
> >I have to assign time values to few variables.
> >How should I do?
> >Let's say I have this variable:
> >
> >dim myTime as Date
> >
> >would it be:
> >(a) mytime=#08:30 Am#
>
> That's ok, but be sure that you do not need a date part.
>
> >or
> >(b) mytime=(8/24) + (30/1440)
>
> Even if that works, it's too obscure to be used. The
> literal in your previous example is much clearer. If you
> are calculating the hous and/or minutes, the TimeSerial
> function is the way to go.
>
> >Since the values will be retrieved from buttons the user will click, I could
> >I assign values through rule (a):
> >Should I write:
> >mytime="#" & buttonclicked & "#"
> >wouldn't this make a string and then raise an error when assigned to a
> >variable declared as Date?
>
> Yes, that will make a string. Use TimeValue (or CDate) if
> all you have is a string that can be converted to a time
> value.
>
> --
> Marsh
> MVP [MS Access]
> .
>
|