-
Solved: Wrong Date capture
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
-
The version of Outlook is 2003
-
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
-
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
-
Hi
I have a same req. Got some idea here..Thanx.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules