Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with Date field

Dustin Wilson
Guest
 
Posts: n/a
#1: Nov 12 '05
I have a problem with the following line of code.

rstOutput![ModifiedDate] = FormatDateTime("January 1, 2004", vbLongDate)

When I run this on my computer at home it runs without problem but when I
run it at work I get a Run-time error '3421' Data type conversion error.
I'm really stumped as to why this is. Both computers are Windows 2000 SP4
with Access 2000. The field [ModifiedDate] is a Date/Time field with a
format of Long Date set. Does anyone have an idea what is going on here?

Thanks
Dustin




Bruce M. Thompson
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Problem with Date field


> I have a problem with the following line of code.[color=blue]
>
> rstOutput![ModifiedDate] = FormatDateTime("January 1, 2004", vbLongDate)
>
> When I run this on my computer at home it runs without problem but when I
> run it at work I get a Run-time error '3421' Data type conversion error.
> I'm really stumped as to why this is. Both computers are Windows 2000 SP4
> with Access 2000. The field [ModifiedDate] is a Date/Time field with a
> format of Long Date set. Does anyone have an idea what is going on here?[/color]

Don't convert your date string to a formatted string, just convert the date
string to a date:

rstOutput![ModifiedDate] = CDate("January 1, 2004")

The actual display of your date value is controlled by the "Format" property of
the field or control, but the actual date value is a number.

--
Bruce M. Thompson, Microsoft Access MVP
bthmpson@mvps.org (See the Access FAQ at http://www.mvps.org/access)[color=blue][color=green]
>> NO Email Please. Keep all communications[/color][/color]
within the newsgroups so that all might benefit.<<


R.A.Balder
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Problem with Date field


I have struggled a lot with similar problems. You will find in the windows
control panel, in Regional settings, settings for long and short date
format. They might be different from one computer to another, and controls
date formats in all your windows programs, and they affect your code.
Putting your database on a server with several users, gets you really into
trouble.
And the trick is: Store only the date value, and use format property to
decide how to display it.

Brgds
Rolf
"Bruce M. Thompson" <bthmpson@big_NOSPAM_foot.com> wrote in message
news:104hfptrt4hsoc4@corp.supernews.com...[color=blue][color=green]
> > I have a problem with the following line of code.
> >
> > rstOutput![ModifiedDate] = FormatDateTime("January 1, 2004", vbLongDate)
> >
> > When I run this on my computer at home it runs without problem but when[/color][/color]
I[color=blue][color=green]
> > run it at work I get a Run-time error '3421' Data type conversion[/color][/color]
error.[color=blue][color=green]
> > I'm really stumped as to why this is. Both computers are Windows 2000[/color][/color]
SP4[color=blue][color=green]
> > with Access 2000. The field [ModifiedDate] is a Date/Time field with a
> > format of Long Date set. Does anyone have an idea what is going on[/color][/color]
here?[color=blue]
>
> Don't convert your date string to a formatted string, just convert the[/color]
date[color=blue]
> string to a date:
>
> rstOutput![ModifiedDate] = CDate("January 1, 2004")
>
> The actual display of your date value is controlled by the "Format"[/color]
property of[color=blue]
> the field or control, but the actual date value is a number.
>
> --
> Bruce M. Thompson, Microsoft Access MVP
> bthmpson@mvps.org (See the Access FAQ at http://www.mvps.org/access)[color=green][color=darkred]
> >> NO Email Please. Keep all communications[/color][/color]
> within the newsgroups so that all might benefit.<<
>
>[/color]


Viper
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Problem with Date field


This is the case between the two machines.. But since others do you it I
have one question that may sound dumb but...

How do you store only the date value?

Thanks
Dustin

"R.A.Balder" <R_A_BALDER@xhotmail.com> wrote in message
news:Ha72c.44415$BD3.8238033@juliett.dax.net...[color=blue]
> I have struggled a lot with similar problems. You will find in the[/color]
windows[color=blue]
> control panel, in Regional settings, settings for long and short date
> format. They might be different from one computer to another, and[/color]
controls[color=blue]
> date formats in all your windows programs, and they affect your code.
> Putting your database on a server with several users, gets you really into
> trouble.
> And the trick is: Store only the date value, and use format property to
> decide how to display it.
>
> Brgds
> Rolf
> "Bruce M. Thompson" <bthmpson@big_NOSPAM_foot.com> wrote in message
> news:104hfptrt4hsoc4@corp.supernews.com...[color=green][color=darkred]
> > > I have a problem with the following line of code.
> > >
> > > rstOutput![ModifiedDate] = FormatDateTime("January 1, 2004",[/color][/color][/color]
vbLongDate)[color=blue][color=green][color=darkred]
> > >
> > > When I run this on my computer at home it runs without problem but[/color][/color][/color]
when[color=blue]
> I[color=green][color=darkred]
> > > run it at work I get a Run-time error '3421' Data type conversion[/color][/color]
> error.[color=green][color=darkred]
> > > I'm really stumped as to why this is. Both computers are Windows 2000[/color][/color]
> SP4[color=green][color=darkred]
> > > with Access 2000. The field [ModifiedDate] is a Date/Time field with[/color][/color][/color]
a[color=blue][color=green][color=darkred]
> > > format of Long Date set. Does anyone have an idea what is going on[/color][/color]
> here?[color=green]
> >
> > Don't convert your date string to a formatted string, just convert the[/color]
> date[color=green]
> > string to a date:
> >
> > rstOutput![ModifiedDate] = CDate("January 1, 2004")
> >
> > The actual display of your date value is controlled by the "Format"[/color]
> property of[color=green]
> > the field or control, but the actual date value is a number.
> >
> > --
> > Bruce M. Thompson, Microsoft Access MVP
> > bthmpson@mvps.org (See the Access FAQ at http://www.mvps.org/access)[color=darkred]
> > >> NO Email Please. Keep all communications[/color]
> > within the newsgroups so that all might benefit.<<
> >
> >[/color]
>
>[/color]


Closed Thread


Similar Microsoft Access / VBA bytes