VB sample code
#1
Scooby Regular
Thread Starter
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes
on
0 Posts
Can anyone send me a bit of vb code to access the inbox of a particular outlook 2000 mailbox and also the property tags for the message items within the folder so I can read them too?
doesn't matter if it's mapi/cdo or outlook.application code.
Many thanks
Fosters
Michael.toye@bmw.co.uk
doesn't matter if it's mapi/cdo or outlook.application code.
Many thanks
Fosters
Michael.toye@bmw.co.uk
#3
Scooby Regular
Thread Starter
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes
on
0 Posts
Seeing as I had to write it myself!!!
If you ever need to update an access table with the messages from an outlook folder then here's the code. I will enhance mine to check, transfer and then remove the messages from the inbox on a timer. (this is for a support desk facility)
Dim oOutlook As New Outlook.Application
Dim oNameSpace As Object
Dim oFolder As MAPIFolder
Dim oInbox As MAPIFolder
Dim Cn As New ADODB.Connection
Function OpenConn2MailboxDB() As Boolean
Dim sCn As String
sCn = "Driver={Microsoft Access Driver (*.mdb)};" & _
"dbq=c:MISFAMailbox.mdb;" & _
"uid=;pwd=;"
Cn.Open sCn
OpenConn2MailboxDB = IIf(Cn.State = 0, False, True)
End Function
Sub CloseConn()
Cn.Close
End Sub
Private Sub Form_Load()
Dim oItem As MailItem
Dim x As Integer
Dim RC As Boolean
Dim RS As New ADODB.Recordset
Dim sSQL As String
RC = OpenConn2MailboxDB
Set oNameSpace = oOutlook.GetNamespace("MAPI")
Set oFolder = oNameSpace.Folders("Mailbox - MIS Finance & Admin Helpdesk")
Set oInbox = oFolder.Folders("Inbox")
'use oFolder.Folders("Inbox").Folders("sub folder name")
'for messages in a subfolder of a main folder
For x = 1 To oInbox.Items.Count
sSQL = "insert into Inbox (Received, Subject, Frm, Bdy) " & _
"values (" & _
"'" & oInbox.Items(x).SentOn & "', " & _
"'" & RQ(oInbox.Items(x).Subject) & "', " & _
"'" & RQ(oInbox.Items(x).SenderName) & "', " & _
"'" & RQ(oInbox.Items(x).Body) & "'" & _
");"
RS.Open sSQL, Cn
Set RS = Nothing
Next x
CloseConn
End Sub
Function RQ(sIn As String) As String
RQ = Replace(sIn, "'", "''")
End Function
If you ever need to update an access table with the messages from an outlook folder then here's the code. I will enhance mine to check, transfer and then remove the messages from the inbox on a timer. (this is for a support desk facility)
Dim oOutlook As New Outlook.Application
Dim oNameSpace As Object
Dim oFolder As MAPIFolder
Dim oInbox As MAPIFolder
Dim Cn As New ADODB.Connection
Function OpenConn2MailboxDB() As Boolean
Dim sCn As String
sCn = "Driver={Microsoft Access Driver (*.mdb)};" & _
"dbq=c:MISFAMailbox.mdb;" & _
"uid=;pwd=;"
Cn.Open sCn
OpenConn2MailboxDB = IIf(Cn.State = 0, False, True)
End Function
Sub CloseConn()
Cn.Close
End Sub
Private Sub Form_Load()
Dim oItem As MailItem
Dim x As Integer
Dim RC As Boolean
Dim RS As New ADODB.Recordset
Dim sSQL As String
RC = OpenConn2MailboxDB
Set oNameSpace = oOutlook.GetNamespace("MAPI")
Set oFolder = oNameSpace.Folders("Mailbox - MIS Finance & Admin Helpdesk")
Set oInbox = oFolder.Folders("Inbox")
'use oFolder.Folders("Inbox").Folders("sub folder name")
'for messages in a subfolder of a main folder
For x = 1 To oInbox.Items.Count
sSQL = "insert into Inbox (Received, Subject, Frm, Bdy) " & _
"values (" & _
"'" & oInbox.Items(x).SentOn & "', " & _
"'" & RQ(oInbox.Items(x).Subject) & "', " & _
"'" & RQ(oInbox.Items(x).SenderName) & "', " & _
"'" & RQ(oInbox.Items(x).Body) & "'" & _
");"
RS.Open sSQL, Cn
Set RS = Nothing
Next x
CloseConn
End Sub
Function RQ(sIn As String) As String
RQ = Replace(sIn, "'", "''")
End Function
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
Sam Witwicky
Engine Management and ECU Remapping
17
13 November 2015 10:49 AM