Date and Time form

J

Jaybird

This should be an easy one... I have a form that is designed to be a log for
entering processes and times. There are several Date/Time entries to be made
on the form. I created a form(frmTime) that pops up when one of the
Date/Time fields are clicked. The user can then input the appropriate date
and time. Well, right now it only works for the [In] field. But, I'd like
to use the same form to enter different data into other Date/Time fields.
Can someone tell me the appropriate technique for this? Here's my code (such
as it is):

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click
Forms![HT Load Info]![In] = Me.Date & " " & Me.Hour & ":" & Me.Min & ":" &
Me.Sec
DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub

As you can see, the values are passed to the main form when the "close"
button is clicked. However, unless I want to make a similar form for ALL of
my Date/Time fields, this technique won't work. I don't know how to make the
current field a variable so that this form will work for all of them.
 
K

Klatuu

What is the purpose of a separate form just to enter time? Why not just use
a text box on the existing form?
Now, there are some issues with your code. First is your naming. Date and
Hour are both reserved words and may very well cause Access some confusion.
And, the & is a concatenation symbol so you may not get the correct results.

To use you form for entering dates in various controls on your main form,
you can use the OpenArgs argument of the OpenForm method to tell your time
entry form where the results gos. First, here is how you would tell the time
form where to put the vaule. Pass the name of the control to the time form:
DoCmd.OpenForm "frmTime", , , , , , "[In]"

Just change the name of the control as necessary.

Now here is how you put the value where you want it:

Forms![HT Load Info].Controls(Me.OpenArgs) = Me.[Date] + _
TimeSerial( Me.[Hour], Me.Min, Me.Sec)

Do your formatting in the IN control on the HT Load Info form.
 
S

Steve

Look at my response to "One Calendar Form For Different Fields" above about
20 posts back. You can use something very similar.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
J

Jaybird

Thanks very much, Dave! I've got several books I'm referencing, but none
have put it as succinctly as this! I will take your advice and change my
field names. To answer your question about the need for such a form... We
have a 'round the clock crew that enters data into this log. The problem has
always been that if there are any calculations to be done with the time data,
shifts that extend past midnight cause a great deal of confusion. My
solution is to have time AND date, so that there can be as little confusion
as possible. I couldn't find a date picker for date and time (at least one
that I could understand how to use), so I created my own. The use of the
concatenation symbol (&) is intentional so that I can use the inputs of the
text boxes in a date/time format --
Why are you asking me? I dont know what Im doing!

Jaybird


Klatuu said:
What is the purpose of a separate form just to enter time? Why not just use
a text box on the existing form?
Now, there are some issues with your code. First is your naming. Date and
Hour are both reserved words and may very well cause Access some confusion.
And, the & is a concatenation symbol so you may not get the correct results.

To use you form for entering dates in various controls on your main form,
you can use the OpenArgs argument of the OpenForm method to tell your time
entry form where the results gos. First, here is how you would tell the time
form where to put the vaule. Pass the name of the control to the time form:
DoCmd.OpenForm "frmTime", , , , , , "[In]"

Just change the name of the control as necessary.

Now here is how you put the value where you want it:

Forms![HT Load Info].Controls(Me.OpenArgs) = Me.[Date] + _
TimeSerial( Me.[Hour], Me.Min, Me.Sec)

Do your formatting in the IN control on the HT Load Info form.

--
Dave Hargis, Microsoft Access MVP


Jaybird said:
This should be an easy one... I have a form that is designed to be a log for
entering processes and times. There are several Date/Time entries to be made
on the form. I created a form(frmTime) that pops up when one of the
Date/Time fields are clicked. The user can then input the appropriate date
and time. Well, right now it only works for the [In] field. But, I'd like
to use the same form to enter different data into other Date/Time fields.
Can someone tell me the appropriate technique for this? Here's my code (such
as it is):

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click
Forms![HT Load Info]![In] = Me.Date & " " & Me.Hour & ":" & Me.Min & ":" &
Me.Sec
DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub

As you can see, the values are passed to the main form when the "close"
button is clicked. However, unless I want to make a similar form for ALL of
my Date/Time fields, this technique won't work. I don't know how to make the
current field a variable so that this form will work for all of them.
 
K

Klatuu

Is the time the employees are entering actual times ( 08:30:00 PM) or are
they time duration? 8 hrs, 30 minutes?
This will make a difference in how you do this. Date/Time fields are not
appropriate for storing durations. They are meant to handle a specific point
in time.
If you want to carry duration, that is a whole different matter.
As to showing as date and time, you still should use the code I presented,
and use the format property of the destination control to format the date and
time.
How data is stored has nothing to do with how it is presented to humans.
--
Dave Hargis, Microsoft Access MVP


Jaybird said:
Thanks very much, Dave! I've got several books I'm referencing, but none
have put it as succinctly as this! I will take your advice and change my
field names. To answer your question about the need for such a form... We
have a 'round the clock crew that enters data into this log. The problem has
always been that if there are any calculations to be done with the time data,
shifts that extend past midnight cause a great deal of confusion. My
solution is to have time AND date, so that there can be as little confusion
as possible. I couldn't find a date picker for date and time (at least one
that I could understand how to use), so I created my own. The use of the
concatenation symbol (&) is intentional so that I can use the inputs of the
text boxes in a date/time format --
Why are you asking me? I dont know what Im doing!

Jaybird


Klatuu said:
What is the purpose of a separate form just to enter time? Why not just use
a text box on the existing form?
Now, there are some issues with your code. First is your naming. Date and
Hour are both reserved words and may very well cause Access some confusion.
And, the & is a concatenation symbol so you may not get the correct results.

To use you form for entering dates in various controls on your main form,
you can use the OpenArgs argument of the OpenForm method to tell your time
entry form where the results gos. First, here is how you would tell the time
form where to put the vaule. Pass the name of the control to the time form:
DoCmd.OpenForm "frmTime", , , , , , "[In]"

Just change the name of the control as necessary.

Now here is how you put the value where you want it:

Forms![HT Load Info].Controls(Me.OpenArgs) = Me.[Date] + _
TimeSerial( Me.[Hour], Me.Min, Me.Sec)

Do your formatting in the IN control on the HT Load Info form.

--
Dave Hargis, Microsoft Access MVP


Jaybird said:
This should be an easy one... I have a form that is designed to be a log for
entering processes and times. There are several Date/Time entries to be made
on the form. I created a form(frmTime) that pops up when one of the
Date/Time fields are clicked. The user can then input the appropriate date
and time. Well, right now it only works for the [In] field. But, I'd like
to use the same form to enter different data into other Date/Time fields.
Can someone tell me the appropriate technique for this? Here's my code (such
as it is):

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click
Forms![HT Load Info]![In] = Me.Date & " " & Me.Hour & ":" & Me.Min & ":" &
Me.Sec
DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub

As you can see, the values are passed to the main form when the "close"
button is clicked. However, unless I want to make a similar form for ALL of
my Date/Time fields, this technique won't work. I don't know how to make the
current field a variable so that this form will work for all of them.
 
J

Jaybird

Right now, all I'm worried about is accurate input of date/time data. If I
have havbe an accurate date associated with an accurate time, then it's a lot
easier to do time calculations and get the expected results. If I ever need
to display these results I'd probably do something like txtTimeElapsed =
Hour([End Time]-[Begin Time] & "Hours" & " " & Minute([End Time]-[Begin
Time] & " " & Second([End Time]-[Begin Time].
--
Why are you asking me? I dont know what Im doing!

Jaybird


Klatuu said:
Is the time the employees are entering actual times ( 08:30:00 PM) or are
they time duration? 8 hrs, 30 minutes?
This will make a difference in how you do this. Date/Time fields are not
appropriate for storing durations. They are meant to handle a specific point
in time.
If you want to carry duration, that is a whole different matter.
As to showing as date and time, you still should use the code I presented,
and use the format property of the destination control to format the date and
time.
How data is stored has nothing to do with how it is presented to humans.
--
Dave Hargis, Microsoft Access MVP


Jaybird said:
Thanks very much, Dave! I've got several books I'm referencing, but none
have put it as succinctly as this! I will take your advice and change my
field names. To answer your question about the need for such a form... We
have a 'round the clock crew that enters data into this log. The problem has
always been that if there are any calculations to be done with the time data,
shifts that extend past midnight cause a great deal of confusion. My
solution is to have time AND date, so that there can be as little confusion
as possible. I couldn't find a date picker for date and time (at least one
that I could understand how to use), so I created my own. The use of the
concatenation symbol (&) is intentional so that I can use the inputs of the
text boxes in a date/time format --
Why are you asking me? I dont know what Im doing!

Jaybird


Klatuu said:
What is the purpose of a separate form just to enter time? Why not just use
a text box on the existing form?
Now, there are some issues with your code. First is your naming. Date and
Hour are both reserved words and may very well cause Access some confusion.
And, the & is a concatenation symbol so you may not get the correct results.

To use you form for entering dates in various controls on your main form,
you can use the OpenArgs argument of the OpenForm method to tell your time
entry form where the results gos. First, here is how you would tell the time
form where to put the vaule. Pass the name of the control to the time form:
DoCmd.OpenForm "frmTime", , , , , , "[In]"

Just change the name of the control as necessary.

Now here is how you put the value where you want it:

Forms![HT Load Info].Controls(Me.OpenArgs) = Me.[Date] + _
TimeSerial( Me.[Hour], Me.Min, Me.Sec)

Do your formatting in the IN control on the HT Load Info form.

--
Dave Hargis, Microsoft Access MVP


:

This should be an easy one... I have a form that is designed to be a log for
entering processes and times. There are several Date/Time entries to be made
on the form. I created a form(frmTime) that pops up when one of the
Date/Time fields are clicked. The user can then input the appropriate date
and time. Well, right now it only works for the [In] field. But, I'd like
to use the same form to enter different data into other Date/Time fields.
Can someone tell me the appropriate technique for this? Here's my code (such
as it is):

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click
Forms![HT Load Info]![In] = Me.Date & " " & Me.Hour & ":" & Me.Min & ":" &
Me.Sec
DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub

As you can see, the values are passed to the main form when the "close"
button is clicked. However, unless I want to make a similar form for ALL of
my Date/Time fields, this technique won't work. I don't know how to make the
current field a variable so that this form will work for all of them.
 
J

Jaybird

Or, rather, something like:

txtTimeElapsed =
Hour([End Time]-[Begin Time] & "Hours" & " " & Minute([End Time]-[Begin
Time] & "Minutes" & " " & Second([End Time]-[Begin Time] & "Seconds"
--
Why are you asking me? I dont know what Im doing!

Jaybird


Jaybird said:
Right now, all I'm worried about is accurate input of date/time data. If I
have havbe an accurate date associated with an accurate time, then it's a lot
easier to do time calculations and get the expected results. If I ever need
to display these results I'd probably do something like txtTimeElapsed =
Hour([End Time]-[Begin Time] & "Hours" & " " & Minute([End Time]-[Begin
Time] & " " & Second([End Time]-[Begin Time].
--
Why are you asking me? I dont know what Im doing!

Jaybird


Klatuu said:
Is the time the employees are entering actual times ( 08:30:00 PM) or are
they time duration? 8 hrs, 30 minutes?
This will make a difference in how you do this. Date/Time fields are not
appropriate for storing durations. They are meant to handle a specific point
in time.
If you want to carry duration, that is a whole different matter.
As to showing as date and time, you still should use the code I presented,
and use the format property of the destination control to format the date and
time.
How data is stored has nothing to do with how it is presented to humans.
--
Dave Hargis, Microsoft Access MVP


Jaybird said:
Thanks very much, Dave! I've got several books I'm referencing, but none
have put it as succinctly as this! I will take your advice and change my
field names. To answer your question about the need for such a form... We
have a 'round the clock crew that enters data into this log. The problem has
always been that if there are any calculations to be done with the time data,
shifts that extend past midnight cause a great deal of confusion. My
solution is to have time AND date, so that there can be as little confusion
as possible. I couldn't find a date picker for date and time (at least one
that I could understand how to use), so I created my own. The use of the
concatenation symbol (&) is intentional so that I can use the inputs of the
text boxes in a date/time format --
Why are you asking me? I dont know what Im doing!

Jaybird


:

What is the purpose of a separate form just to enter time? Why not just use
a text box on the existing form?
Now, there are some issues with your code. First is your naming. Date and
Hour are both reserved words and may very well cause Access some confusion.
And, the & is a concatenation symbol so you may not get the correct results.

To use you form for entering dates in various controls on your main form,
you can use the OpenArgs argument of the OpenForm method to tell your time
entry form where the results gos. First, here is how you would tell the time
form where to put the vaule. Pass the name of the control to the time form:
DoCmd.OpenForm "frmTime", , , , , , "[In]"

Just change the name of the control as necessary.

Now here is how you put the value where you want it:

Forms![HT Load Info].Controls(Me.OpenArgs) = Me.[Date] + _
TimeSerial( Me.[Hour], Me.Min, Me.Sec)

Do your formatting in the IN control on the HT Load Info form.

--
Dave Hargis, Microsoft Access MVP


:

This should be an easy one... I have a form that is designed to be a log for
entering processes and times. There are several Date/Time entries to be made
on the form. I created a form(frmTime) that pops up when one of the
Date/Time fields are clicked. The user can then input the appropriate date
and time. Well, right now it only works for the [In] field. But, I'd like
to use the same form to enter different data into other Date/Time fields.
Can someone tell me the appropriate technique for this? Here's my code (such
as it is):

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click
Forms![HT Load Info]![In] = Me.Date & " " & Me.Hour & ":" & Me.Min & ":" &
Me.Sec
DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub

As you can see, the values are passed to the main form when the "close"
button is clicked. However, unless I want to make a similar form for ALL of
my Date/Time fields, this technique won't work. I don't know how to make the
current field a variable so that this form will work for all of them.
 

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

Similar Threads


Top