PC Review


Reply
Thread Tools Rate Thread

Date woes using VBA

 
 
Dave Reardon
Guest
Posts: n/a
 
      12th Feb 2010
I have a table with a field for dates, which contains four rows. I am
attempting to use the first date to populate a field in a different table,
using an update query written in SQL. The syntax is:
rs.ActiveConnection = DR

rs.Open "AttDatesT"

With rs
rs.MoveFirst
datDate = .Fields("DateId")

MsgBox strDate
strSQL1 = "UPDATE [Students-T] SET [Students-T].Date1 = "
DoCmd.RunSQL strSQL1 & datDate
End With
rs.Close

The message box displays the date correctly, eg 10/02/2010 but when I go to
the field to look at the data in the table it typically displays something
like 00:03:35 I assume it is to do with a date conversion, but I don't seem
to find any reference to this anywhere. Any help very welcome.

 
Reply With Quote
 
 
 
 
RonaldoOneNil
Guest
Posts: n/a
 
      12th Feb 2010
Not tested but try this

strSQL1 = "UPDATE [Students-T] SET [Students-T].Date1 = #"
DoCmd.RunSQL strSQL1 & datDate & "#"


"Dave Reardon" wrote:

> I have a table with a field for dates, which contains four rows. I am
> attempting to use the first date to populate a field in a different table,
> using an update query written in SQL. The syntax is:
> rs.ActiveConnection = DR
>
> rs.Open "AttDatesT"
>
> With rs
> rs.MoveFirst
> datDate = .Fields("DateId")
>
> MsgBox strDate
> strSQL1 = "UPDATE [Students-T] SET [Students-T].Date1 = "
> DoCmd.RunSQL strSQL1 & datDate
> End With
> rs.Close
>
> The message box displays the date correctly, eg 10/02/2010 but when I go to
> the field to look at the data in the table it typically displays something
> like 00:03:35 I assume it is to do with a date conversion, but I don't seem
> to find any reference to this anywhere. Any help very welcome.
>

 
Reply With Quote
 
MPM1100
Guest
Posts: n/a
 
      12th Feb 2010
As specified in the last post, you do need to provide the format charcter for
dates "#" on either side of your variable. You should also check the
recipient field to ensure that it is a date field that it isn't formatted
adversely. It looks as though you have a time format in that field.

"Dave Reardon" wrote:

> I have a table with a field for dates, which contains four rows. I am
> attempting to use the first date to populate a field in a different table,
> using an update query written in SQL. The syntax is:
> rs.ActiveConnection = DR
>
> rs.Open "AttDatesT"
>
> With rs
> rs.MoveFirst
> datDate = .Fields("DateId")
>
> MsgBox strDate
> strSQL1 = "UPDATE [Students-T] SET [Students-T].Date1 = "
> DoCmd.RunSQL strSQL1 & datDate
> End With
> rs.Close
>
> The message box displays the date correctly, eg 10/02/2010 but when I go to
> the field to look at the data in the table it typically displays something
> like 00:03:35 I assume it is to do with a date conversion, but I don't seem
> to find any reference to this anywhere. Any help very welcome.
>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      12th Feb 2010
MsgBox is using a variable strDate and the SQL statement is using a variable
named datDate.

Assuming that datDate is actually getting the same date and is a datetype you
need to modify your sql string so it has the date delimiters # surrounding the
date. RIght Now you are passing in the result of a division so Dec 30 2000 is
probably the results of dividing 12 by 30 and then dividing that by 2000 which
is going to give you a rather small decimal fraction on the zero day.

DoCmd.RunSQL strSQL1 & Format(datDate,"\#yyyy-mm-dd\#")

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Dave Reardon wrote:
> I have a table with a field for dates, which contains four rows. I am
> attempting to use the first date to populate a field in a different table,
> using an update query written in SQL. The syntax is:
> rs.ActiveConnection = DR
>
> rs.Open "AttDatesT"
>
> With rs
> rs.MoveFirst
> datDate = .Fields("DateId")
>
> MsgBox strDate
> strSQL1 = "UPDATE [Students-T] SET [Students-T].Date1 = "
> DoCmd.RunSQL strSQL1 & datDate
> End With
> rs.Close
>
> The message box displays the date correctly, eg 10/02/2010 but when I go to
> the field to look at the data in the table it typically displays something
> like 00:03:35 I assume it is to do with a date conversion, but I don't seem
> to find any reference to this anywhere. Any help very welcome.
>

 
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
Outlook 2003: Flag for Follow Up Completed On Date Woes John Ritterbush Microsoft Outlook Discussion 3 17th Apr 2008 06:40 AM
Future Date Woes Kevin Microsoft VB .NET 5 1st Jan 2007 04:41 PM
Date Cell/ Format woes! dancleary Microsoft Excel Misc 1 26th Jun 2006 10:44 AM
Date Formatting Woes Minitman Microsoft Excel Programming 7 16th Dec 2004 03:11 PM
Date Woes Kevin Vaughn Microsoft ASP .NET 3 3rd Jul 2003 08:32 PM


Features
 

Advertising
 

Newsgroups
 


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