PC Review


Reply
Thread Tools Rate Thread

Date + Time Problem

 
 
DEI
Guest
Posts: n/a
 
      27th Jul 2008
I have a form with fields for entry of times in short time format. I would
like the user to enter only the 'short time' only, eg. '13:24', but then I
would like to actually store the data in the underlying table with the
complete date and time, eg. '7/24/2008 1:24 PM'.

I have code in the after update event that adds the date to the time:

Me.field1 = field1 + [Date]

However, the [Date] is actually a date entered in a field on another open
form that is an unbound control, in short date format. I sometimes get a
'type mismatch' error; the date entered in the unbound control is recognized
as text and not a date.

What is further problematic is that it does not always happen on all
workstations, i.e some users get the error and others do not.

Is there anything I can do to keep this from happenning?

Thanks in advance.

DEI


 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      27th Jul 2008
Suggestions:

1. Change the name of the text box on the other from to (say) txtDate.

2. If txtDate is unbound (not bound to a date/time field), set the Format
property of the text box to Short Date or similiar, so it won't accept
non-date values.

3. Make sure you don't assign a non-date value to txtDate (e.g.
programmatically, or by its default value, etc.)

4. In your code, make sure the other form is open, and that txtDate contains
a valid date.

5. You may also want to check that Field1 is actually a time value without a
date, and that txtDate is a date without a time component.

This kind of thing:

If Me.Field1 Between #00:00:00# And #23:59:59# Then
If CurrentProject.AllForms("Form2").IsLoaded Then
If IsDate(Forms!Form2!txtDate) Then
Me.Field1 = DateValue(Forms!Form2!txtDate) + Me.Field1
End If
End If
End If

(The conditions there also elimnate nulls.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"DEI" <(E-Mail Removed)> wrote in message
news:3199E60D-5504-43BE-9CA2-(E-Mail Removed)...
>I have a form with fields for entry of times in short time format. I would
> like the user to enter only the 'short time' only, eg. '13:24', but then I
> would like to actually store the data in the underlying table with the
> complete date and time, eg. '7/24/2008 1:24 PM'.
>
> I have code in the after update event that adds the date to the time:
>
> Me.field1 = field1 + [Date]
>
> However, the [Date] is actually a date entered in a field on another open
> form that is an unbound control, in short date format. I sometimes get a
> 'type mismatch' error; the date entered in the unbound control is
> recognized
> as text and not a date.
>
> What is further problematic is that it does not always happen on all
> workstations, i.e some users get the error and others do not.
>
> Is there anything I can do to keep this from happenning?
>
> Thanks in advance.
>
> DEI


 
Reply With Quote
 
DEI
Guest
Posts: n/a
 
      4th Aug 2008
Allen,

Thanks for your help. I used the code you suggested, but dealt with null
values at the AfterUpdate event of each field and created an 'AddDate' public
function:

AfterUpdate Code:

If Not IsNull(Field1) Then
Me.Field1 = AddDate(Field1)
End If

AddDate Function:

If Field1 >= #12:00:00 AM# And TimeField <= #11:59:59 PM# Then
If CurrentProject.AllForms("Form").IsLoaded Then
If IsDate(Forms![Form]![txtDate]) Then
AddDate = DateValue(Forms![Form]![txtDate]) + Field1
End If
End If
End If

Thanks again.


"Allen Browne" wrote:

> Suggestions:
>
> 1. Change the name of the text box on the other from to (say) txtDate.
>
> 2. If txtDate is unbound (not bound to a date/time field), set the Format
> property of the text box to Short Date or similiar, so it won't accept
> non-date values.
>
> 3. Make sure you don't assign a non-date value to txtDate (e.g.
> programmatically, or by its default value, etc.)
>
> 4. In your code, make sure the other form is open, and that txtDate contains
> a valid date.
>
> 5. You may also want to check that Field1 is actually a time value without a
> date, and that txtDate is a date without a time component.
>
> This kind of thing:
>
> If Me.Field1 Between #00:00:00# And #23:59:59# Then
> If CurrentProject.AllForms("Form2").IsLoaded Then
> If IsDate(Forms!Form2!txtDate) Then
> Me.Field1 = DateValue(Forms!Form2!txtDate) + Me.Field1
> End If
> End If
> End If
>
> (The conditions there also elimnate nulls.)
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "DEI" <(E-Mail Removed)> wrote in message
> news:3199E60D-5504-43BE-9CA2-(E-Mail Removed)...
> >I have a form with fields for entry of times in short time format. I would
> > like the user to enter only the 'short time' only, eg. '13:24', but then I
> > would like to actually store the data in the underlying table with the
> > complete date and time, eg. '7/24/2008 1:24 PM'.
> >
> > I have code in the after update event that adds the date to the time:
> >
> > Me.field1 = field1 + [Date]
> >
> > However, the [Date] is actually a date entered in a field on another open
> > form that is an unbound control, in short date format. I sometimes get a
> > 'type mismatch' error; the date entered in the unbound control is
> > recognized
> > as text and not a date.
> >
> > What is further problematic is that it does not always happen on all
> > workstations, i.e some users get the error and others do not.
> >
> > Is there anything I can do to keep this from happenning?
> >
> > Thanks in advance.
> >
> > DEI

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using Date() for default value in my Date/Time field Marshall Microsoft Access Database Table Design 4 19th Oct 2009 03:58 PM
Calculating days & time left from start date/time to end date/time =?Utf-8?B?bWFyaWU=?= Microsoft Excel Worksheet Functions 7 7th Dec 2005 02:36 PM
Problem sending date to SQL date time field Robin Microsoft ASP .NET 2 4th Aug 2004 06:27 PM
Calc. Length of time with time-in, time-out, date-in, date-out in diff. columns Niceven Microsoft Excel Misc 2 28th May 2004 04:31 PM
problem with date time field - if time=midnight loose time Michael San Filippo Microsoft Access VBA Modules 5 3rd Dec 2003 05:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 AM.