Log in

View Full Version : Solved: Wrong Date capture



kbsudhir
12-18-2007, 03:27 PM
Hi

I am using Itemadd event to capturing the attributes of the outgoing mail.
But it is capturing wrong date time.


Code:

Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=D:\Projects\Access-Outlook\Outlook.mdb;"
'open a recordset
Set rs = New ADODB.Recordset
rs.Open "select * from SentItems", cn, adOpenStatic, adLockOptimistic

rs.AddNew

rs.Fields("ConversationIndex") = item.ConversationIndex
rs.Fields("Identifier") = Left(item.ConversationIndex, 40)
rs.Fields("Subject") = item.Subject
rs.Fields("SentDateTIme") = item.SentOn
rs.Fields("Recipients") = item.To
rs.Fields("CC") = item.CC
rs.Fields("MessageBody") = item.Body
rs.Fields("Importance") = item.Importance
rs.Fields("User") = VBA.Environ("UserName")



rs.Update
rs.Close

End Sub
It is capturing date as 1/1/4501

Can You please let me what is causing this error and what is its resolution

Please help
:help

kbsudhir
12-18-2007, 03:29 PM
The version of Outlook is 2003

orange
12-19-2007, 07:36 AM
I'm not an outlook expert by any means. I did check some outlook vba I have written to confirm the field:
Debug.Print olitem.SentOn
and I am getting the proper Date and Time from my selected outlook record.\

My guess, and it's purely a guess, is that there is an issue with the format of the date field when it gets to Access. Perhaps it's a text field and needs to be converted to a Date...

Try it with a CDate function in Access or print combinations of the field as a test.

Good luck

kbsudhir
12-19-2007, 09:21 AM
Hi Orange,

Thanks for your time but I tried that also but of no use. Tried by pulling the data to excel cell which was in date format but no use.

It should capture the timewhen I am sending the mail i.e. the time when I press send.

What I have done now is I am capturing the system date n time at that moment.

Here is the code -

Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=D:\Projects\Outlook.mdb;"
'open a recordset
Set rs = New ADODB.Recordset
rs.Open "select * from SentItems", cn, adOpenStatic, adLockOptimistic

rs.AddNew

rs.Fields("ConversationIndex") = item.ConversationIndex
rs.Fields("Identifier") = Left(item.ConversationIndex, 40)
rs.Fields("Subject") = item.Subject
rs.Fields("SentDate") = Date 'Capturing the system date
rs.Fields("SentTime") = Time 'Capturing the system time
rs.Fields("Recipients") = item.To
rs.Fields("CC") = item.CC
rs.Fields("MessageBody") = item.Body
rs.Fields("Importance") = item.Importance
rs.Fields("User") = VBA.Environ("UserName") ' This line will capture user.

rs.Update
rs.Close

End Sub

I appreciate the time given by you on this. I hope this code help in some way, in any ofyour projects.

Thanks
Sudhir

:friends: :content:

itanand
02-04-2008, 08:11 AM
I have a same req. Got some idea here..Thanx.