Results 1 to 34 of 34

Thread: Import E-Mails from Outlook to Access, and read them from Access?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Question Re: Import E-Mails from Outlook to Access, and read them from Access?

    Hi RobDog,

    I am reviving this thread since I have a question about this code.

    I'm not going to lie, I am a complete NEWB when it comes to linking MS apps. And since you are a GOD when it comes to this stuff, I am going to ask some very newb questions about the code you have posted. (So please go easy on me )

    I have added the code above (the code with the 3 parts to it) to a module in Outlook. There in lies my first question - where do I place this code? The Form_Open() sub makes me think that the code should be placed in a form module, if not what does it refer to? At any rate, I have tried the code in both a module and form code and have come across this error: "Run-time eorr 3709: The connection cannot be used to perform this operation. It is either closed or invalid in this context."
    This refers to this line of code:
    VB Code:
    1. goRs.Open sSQL, CnnA, adOpenKeyset, adLockOptimistic, adCmdText

    I have set the following references set:
    - VBA
    - MS Outlook 11.0 Object Library
    - OLE
    - MS Office 11.0 Object Library
    - MS Forms 2.0 Obj Library
    - MS ADO (multi-dim) 2.8 Library
    - MS ADO 2.0 Library

    I tried to set more ADO Libraries but I would get a "Name conflicts with existing module, project, or object library" Error. Are there any other references that I need to set?

    Any idea why the code is not working??
    As always, your help is very much appreciated!!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    In order to get a better picture, why do you have OLE and MS Forms? Are you doing this in VB6 or in Outlook VBA or Access?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    To be honest, I'm not really sure why I have those references set. In fact, I'm pretty sure those may have been already set when I checked the references list.

    To answer your question, I am doing this in Outlook VBA. I think I should be putting the Form_Load sub into an Access form that shows the inbox email... is that right? I do have a table called [Inbox]. Is there anything else i am missing?

    I tried adding the Form_Load sub into a form in Access and it complained about the Set oApp = New Outlook.Application as if it doesn't understand what Outlook.Application is.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Maybe I should give you a little insight into what I am doing. I have a database that tracks engineering Issues. My end goal is allow the user to add issues to the database through Outlook. I guess a way to implement this would be to have an email open in Outlook and then click a button to export the email to the database (I already have a menubar button added thanks to your other code - and don't worry, you have TONS of props in my code!!!!) The fields that I would need to use would be the header info (from, to, time, etc.) and then the body and subject of the email. All of this would be used to create a new issue in the database. if there are any attachments in the email, they also need to be accessed from the database (which you have already addressed in this thread).

    The reason I am asking you all of these questions about your code is so that I can understand how you are implementing it and then customize it for my specific project. But if you would like to help me out with that, I won't be complaining one bit !! Thanks for the help in advance, you always play such a huge role in getting everyone's code in working order - and it doesn't go unnoticed!!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    So here's a little more clarification... the references I was referring to were my Outlook references. I now have set my Access references to include Outlook Object Library.

    Now, I have included the Form_Load sub into my Access VBA (which is what I think I'm supposed to do, but I'm not sure). This is what I added to my [Form_Import from Outlook TEST] code:
    VB Code:
    1. Option Compare Database
    2. Private oApp As Outlook.Application
    3. Private oNS As Outlook.NameSpace
    4. Private oInbox As Outlook.MAPIFolder
    5. Private oTasks As Outlook.MAPIFolder
    6. Private CnnA As ADODB.Connection
    7.  
    8. Private Sub Form_Load()
    9.  
    10.     Set oApp = New Outlook.Application
    11.     Set oNS = oApp.GetNamespace("MAPI")
    12.     Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
    13.     Set oTasks = oNS.GetDefaultFolder(olFolderTasks)
    14.     'MUST BE A FOLDER WITH A DEFAULT MESSAGE TYPE OF POST!!!
    15.     'RIGHT CLICK ON THE DESIRED NEW FOLDER AND CLICK PROPERTIES.
    16.     'THEN LOOK AT THE BOTTON AND IT SHOULD SAY -
    17.     '"WHEN POSTING TO THIS FOLDER, USE: POST"
    18. '    Set oInbox = oNS.Folders("Your Custom Folder Name Here!")
    19.    
    20.     Set CnnA = New ADODB.Connection
    21.     CnnA.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & txtDBPath & ";Persist Security Info=False"
    22.     CnnA.Open
    23.    
    24. End Sub

    When the code gets to the last line (CnnA.Open) it give me the "Authentication Failed" error. Any ideas?

    So now if I can figure out why the Connection is being refused, that will get rid of my first error in Outlook (the 3709 run-time error)
    Last edited by RiceRocket; Apr 3rd, 2006 at 11:15 AM.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    This is a two part issue. First part is to export the emails to the Access table. This is done in the Outlook VBA code part. Then to read/view tehm you need to do it from Access.

    So first part you will need a reference to MS ADO 2.x Object Library.

    Second part you need a reference to MS Outlook xx.0 Object Library

    Now to throw a wrench in the works, do your users need a real time listing of the emails in Access to match whats in Outlook?

    I think I wil split this off to a new thread referencing this one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Thread split from this one located here - http://www.vbforums.com/showthread.php?t=264040




    The issue is probably from the connectionstring not being completely correct as it had a textbox in it which you probably dont need. Just hard code in the db path or use Application.Path.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Alright, I am an idiot (as if you didn't already figure that out). I had to replace the txtDBPath (duhhhhhh). Well, I did that and then I attempt to run the Outlook_Emails_2_Access sub (in Outlook), I get the "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another" when I get to this line:

    VB Code:
    1. goRs.Open sSQL, CnnA, adOpenKeyset, adLockOptimistic, adCmdText

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Whats your sSQL look like?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Sorry I split the thread like that, I'm not entirely sure how I even did it!! Anyway, I posted a reply on that thread. Thanks robdog!

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    VB Code:
    1. sSQL = "SELECT * FROM [Inbox] WHERE 1=2;"

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    I did that split as to keep the thread starters issue on topic and created a new thread just for yours.

    This is the thread to post in now.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Do you have a table called Inbox in Access?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Alright, I am an idiot (as if you didn't already figure that out). I had to replace the txtDBPath (duhhhhhh). Well, I did that and then I attempt to run the Outlook_Emails_2_Access sub (in Outlook), I get the "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another" when I get to this line:

    VB Code:
    1. goRs.Open sSQL, CnnA, adOpenKeyset, adLockOptimistic, adCmdText

    To answer your first question, the listing of emails in Access only needs to be the emails that pertain to each issue, it does not need to match ALL of the emails in Outlook. So for example, I have an Issues table that contains all of my issues. There is a "Comments" field in the table in which i want the body of the email from Outlook to go to. I would then like to include the attachments (somehow - I guess I can add a combobox to my form like you said earlier in the thread).

    So when the user opens up an email (from Outlook) that contains an engineering issue, they can then click a button and the contents of the email will be added as a new record in the Issues table. I can list out all of the fields of the issue table if you want me to.

    To answer your second question, yes I do have a table in Access named [Inbox].

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Ok, to refresh my memory and make sure we are talking about the same part, your in access trying to connect to the Outlook Inbox with the goRs object?

    You see there are two possible ways to connect to Outlook from Access. One is using ADO and the other is using the Outlook Object Model.

    Which part are you wanting to start on first and we will go from there.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    I'll detail it out a little (sorry for the confusion... i am confusing myself so I'm sure its not easy for you either!!)

    In access, I have a formed called "Import from Outlook TEST." For the Form_Load event on that form I have the following code (which executes with NO errors):

    VB Code:
    1. Option Compare Database
    2. Private oApp As Outlook.Application
    3. Private oNS As Outlook.NameSpace
    4. Private oInbox As Outlook.MAPIFolder
    5. Private oTasks As Outlook.MAPIFolder
    6. Private CnnA As ADODB.Connection
    7.  
    8. Private Sub Form_Load()
    9.  
    10.     Set oApp = New Outlook.Application
    11.     Set oNS = oApp.GetNamespace("MAPI")
    12.     Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
    13.     Set oTasks = oNS.GetDefaultFolder(olFolderTasks)
    14.     'MUST BE A FOLDER WITH A DEFAULT MESSAGE TYPE OF POST!!!
    15.     'RIGHT CLICK ON THE DESIRED NEW FOLDER AND CLICK PROPERTIES.
    16.     'THEN LOOK AT THE BOTTON AND IT SHOULD SAY -
    17.     '"WHEN POSTING TO THIS FOLDER, USE: POST"
    18. '    Set oInbox = oNS.Folders("Your Custom Folder Name Here!")
    19.    
    20.     Set CnnA = New ADODB.Connection
    21.     CnnA.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\Documents and Settings\edmastro.AMR\My Documents\Issues Database.mdb" & "; Persist Security Info=False"
    22.     CnnA.Open
    23.    
    24. End Sub

    (Rest of code posted on new reply due to length)

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Then, in Outlook, I have a module that contains the rest of the code (activated by a button click) Here is the rest of the code:

    VB Code:
    1. 'Option Explicit
    2.  
    3. 'Private oApp As Outlook.Application
    4. 'Private oNS As Outlook.NameSpace
    5. 'Private oInbox As Outlook.MAPIFolder
    6. 'Private oTasks As Outlook.MAPIFolder
    7. 'Private CnnA As ADODB.Connection
    8.  
    9. Private Sub cmdExportEmails_Click()
    10.  
    11.     Call Outlook_Emails_2_Access
    12.  
    13. End Sub
    14.  
    15. 'Private Sub Form_Load()
    16. '
    17.  '   Set oApp = New Outlook.Application
    18.   '  Set oNS = oApp.GetNamespace("MAPI")
    19.    ' Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
    20.     'Set oTasks = oNS.GetDefaultFolder(olFolderTasks)
    21.     'MUST BE A FOLDER WITH A DEFAULT MESSAGE TYPE OF POST!!!
    22.     'RIGHT CLICK ON THE DESIRED NEW FOLDER AND CLICK PROPERTIES.
    23.     'THEN LOOK AT THE BOTTON AND IT SHOULD SAY -
    24.     '"WHEN POSTING TO THIS FOLDER, USE: POST"
    25. '    Set oInbox = oNS.Folders("Your Custom Folder Name Here!")
    26.    
    27.     'Set CnnA = New ADODB.Connection
    28.     'CnnA.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & txtDBPath & ";Persist Security Info=False"
    29.     'CnnA.Open
    30.    
    31. 'End Sub
    32.  
    33. Private Function Outlook_Emails_2_Access()
    34. '   <GORS = ACCESS>
    35.     On Error GoTo No_Bugs
    36.  
    37.     Dim goRs As ADODB.Recordset
    38.    
    39.     Dim oEmail As Outlook.MailItem
    40.     Dim oMeetingType As Outlook.MeetingItem
    41.     Dim oDistributionList As Outlook.DistListItem
    42.    
    43.     Dim vType As Variant
    44.    
    45.     Dim i As Integer
    46.     Dim ii As Integer
    47.    
    48.     Dim sAttachment As String
    49.    
    50.     Dim sSQL As String
    51.    
    52.     Set goRs = New ADODB.Recordset
    53.    
    54.     sSQL = "SELECT * FROM [Inbox] WHERE 1=2;"
    55.     goRs.Open sSQL, CnnA, adOpenKeyset, adLockOptimistic, adCmdText
    56.    
    57.     prbProgress.Max = oInbox.Items.Count
    58.     i = 1
    59.     Do While i <= oInbox.Items.Count
    60.         DoEvents
    61.         Select Case oInbox.Items(i).Class
    62.             Case olMail
    63.                 vType = "Email"
    64.             Case olMeetingRequest
    65.                 vType = "MeetingItem"
    66.             Case olMeetingResponseNegative
    67.                 vType = "MeetingItem"
    68.             Case olMeetingResponsePositive
    69.                 vType = "MeetingItem"
    70.             Case olMeetingResponseTentative
    71.                 vType = "MeetingItem"
    72.             Case olDistributionList
    73.                 vType = "DistListItem"
    74.         End Select
    75.         If vType = "Email" Then 'ONLY EMAIL TYPES
    76.             Set oEmail = oInbox.Items(i)
    77.             If FindOutlookEmail(oEmail.EntryID) = False Then
    78.                 'ADDED FOR TESTING ONLY SO YOU CAN SEE HOW TO PASS THE ITEMS.
    79.                 'TAKE OUT AND PLACE WHERE YOU ARE CALLING IT FROM
    80.                 'OTHERWISE IT WILL OPEN ALL EXPORTED EMAILS
    81.                 Call OpenOutlookEmail(oEmail.EntryID, CStr(oInbox.Items(i).Class))
    82.                 goRs.AddNew
    83.                 goRs!To = oEmail.To
    84.                 goRs!CC = oEmail.CC
    85.                 goRs!BCC = oEmail.BCC
    86.                 goRs!Subject = oEmail.Subject
    87.                 goRs!Body = oEmail.Body           'PLAIN TEXT BODY NOTES
    88.                 goRs!HTMLBody = oEmail.HTMLBody   'HTML BODY NOTES
    89.                 goRs!Importance = oEmail.Importance
    90.                 goRs!Received = oEmail.ReceivedTime
    91.                 goRs!Class = oEmail.Class 'EMAIL, MEETING RESPONSE, MEETING REQUEST, DIST. LIST, ETC.
    92.                 goRs!ReceivedByName = oEmail.ReceivedByName
    93.                 goRs!EntryID = oEmail.EntryID
    94.                 If oEmail.Attachments.Count > 1 Then
    95.                     'LOOP THROUGH ALL ATTACHMENTS SAVING TO DIRECTORY AND ENTERING FILENAME INTO FIELD
    96.                     For ii = 1 To oEmail.Attachments.Count
    97.                         'DETERMINE ATTACHMENT CLASS TYPE ATTACHED, LINKED, EMBEDDED, OR OLE
    98.                         If oEmail.Attachments.Item(ii).Type = olByValue Or oEmail.Attachments.Item(ii).Type = olEmbeddeditem Then
    99.                             oEmail.Attachments.Item(ii).SaveAsFile "C:\MyOutlookEmailExport\Attachments\" & oEmail.Attachments.Item(ii).FileName
    100.                             sAttachment = sAttachment & "C:\MyOutlookEmailExport\Attachments\" & oEmail.Attachments.Item(ii).FileName & vbNewLine
    101.                         End If
    102.                     Next
    103.                     goRs!Attachment = sAttachment
    104.                 Else
    105.                     goRs!Attachment = "None"
    106.                 End If
    107.                 'CONTINUE ON WITH OTHER FIELD YOU WANT
    108.                 '...
    109.                 goRs.Update
    110.             End If
    111.             Set oEmail = Nothing
    112.         ElseIf vType = "MeetingItem" Then
    113.             Set oMeetingType = oInbox.Items(i)
    114.             If FindOutlookEmail(oMeetingType.EntryID) = False Then
    115.                 goRs.AddNew
    116.                 goRs!To = oMeetingType.Recipients.Item(1).Name
    117.                 goRs!CC = IIf(oMeetingType.Recipients.Count > 1, oMeetingType.Recipients.Item(2).Name, "")
    118.                 goRs!BCC = ""
    119.                 goRs!Subject = oMeetingType.Subject
    120.                 goRs!Body = oMeetingType.Body           'PLAIN TEXT BODY NOTES
    121.                 goRs!HTMLBody = ""
    122.                 goRs!Importance = oMeetingType.Importance
    123.                 goRs!Received = oMeetingType.ReceivedTime
    124.                 goRs!Class = oMeetingType.Class 'EMAIL, MEETING RESPONSE, MEETING REQUEST, DIST. LIST, ETC.
    125.                 goRs!ReceivedByName = ""
    126.                 goRs!EntryID = oMeetingType.EntryID
    127.                 If oMeetingType.Attachments.Count > 1 Then
    128.                     'LOOP THROUGH ALL ATTACHMENTS SAVING TO DIRECTORY AND ENTERING FILENAME INTO FIELD
    129.                     For ii = 1 To oMeetingType.Attachments.Count
    130.                         'DETERMINE ATTACHMENT CLASS TYPE ATTACHED, LINKED, EMBEDDED, OR OLE
    131.                         If oMeetingType.Attachments.Item(ii).Type = olByValue Or oMeetingType.Attachments.Item(ii).Type = olEmbeddeditem Then
    132.                             oMeetingType.Attachments.Item(ii).SaveAsFile "C:\MyOutlookEmailExport\Attachments\" & oMeetingType.Attachments.Item(ii).FileName
    133.                             sAttachment = sAttachment & "C:\MyOutlookEmailExport\Attachments\" & oMeetingType.Attachments.Item(ii).FileName & vbNewLine
    134.                         End If
    135.                     Next
    136.                     goRs!Attachment = sAttachment
    137.                 Else
    138.                     goRs!Attachment = "None"
    139.                 End If
    140.                 'CONTINUE ON WITH OTHER FIELD YOU WANT
    141.                 '...
    142.                 goRs.Update
    143.             End If
    144.             Set oMeetingType = Nothing
    145.         ElseIf vType = "DistListItem" Then
    146.             Set oDistributionList = oInbox.Items(i)
    147.             If FindOutlookEmail(oDistributionList.EntryID) = False Then
    148.                 goRs.AddNew
    149.                 goRs!To = oDistributionList.DLName
    150.                 goRs!CC = oDistributionList.MemberCount & "-Members"
    151.                 goRs!BCC = ""
    152.                 goRs!Subject = oDistributionList.Subject
    153.                 goRs!Body = oDistributionList.Body           'PLAIN TEXT BODY NOTES
    154.                 goRs!HTMLBody = ""
    155.                 goRs!Importance = oDistributionList.Importance
    156.                 goRs!Received = ""
    157.                 goRs!Class = oDistributionList.Class 'EMAIL, MEETING RESPONSE, MEETING REQUEST, DIST. LIST, ETC.
    158.                 goRs!ReceivedByName = ""
    159.                 goRs!EntryID = oDistributionList.EntryID
    160.                 If oDistributionList.Attachments.Count > 1 Then
    161.                     'LOOP THROUGH ALL ATTACHMENTS SAVING TO DIRECTORY AND ENTERING FILENAME INTO FIELD
    162.                     For ii = 1 To oDistributionList.Attachments.Count
    163.                         'DETERMINE ATTACHMENT CLASS TYPE ATTACHED, LINKED, EMBEDDED, OR OLE
    164.                         If oDistributionList.Attachments.Item(ii).Type = olByValue Or oDistributionList.Attachments.Item(ii).Type = olEmbeddeditem Then
    165.                             oDistributionList.Attachments.Item(ii).SaveAsFile "C:\MyOutlookEmailExport\Attachments\" & oDistributionList.Attachments.Item(ii).FileName
    166.                             sAttachment = sAttachment & "C:\MyOutlookEmailExport\Attachments\" & oDistributionList.Attachments.Item(ii).FileName & vbNewLine
    167.                         End If
    168.                     Next
    169.                     goRs!Attachment = sAttachment
    170.                 Else
    171.                     goRs!Attachment = "None"
    172.                 End If
    173.                 'CONTINUE ON WITH OTHER FIELD YOU WANT
    174.                 '...
    175.                 goRs.Update
    176.             End If
    177.             Set oDistributionList = Nothing
    178.         Else
    179.             MsgBox "Unsupported message type!", vbOKOnly + vbExclamation
    180.         End If
    181.         Set oEmail = Nothing
    182.         prbProgress.Value = i
    183.         i = i + 1
    184.     Loop
    185.    
    186.     Set oInbox = Nothing
    187.     Set oNS = Nothing
    188.     goRs.Close
    189.     Set CnnA = Nothing
    190.     Set goRs = Nothing
    191.     Exit Function
    192.  
    193. No_Bugs:
    194.    
    195.     MsgBox Err.Number & "-" & Err.Description, vbCritical, "Outlook Email Export"
    196.     Resume
    197.  
    198. End Function
    199.  
    200. ''''''''''2nd 3rd
    201.  
    202. Private Function FindOutlookEmail(ByVal oEmailEntryID As String) As Boolean
    203.  
    204.     Dim oRsAccessEmail As ADODB.Recordset 'EMAIL IN ACCESS TO CHECK AGAINST
    205.    
    206.     Dim i As Integer
    207.    
    208.     Set oRsAccessEmail = New ADODB.Recordset
    209.     oRsAccessEmail.Open "SELECT EntryID FROM Inbox WHERE EntryID = '" & oEmailEntryID & "';", CnnA, adOpenKeyset, adLockReadOnly, adCmdText
    210.     If oRsAccessEmail.BOF = True And oRsAccessEmail.EOF = True Then
    211.         FindOutlookEmail = False
    212.     Else
    213.         FindOutlookEmail = True
    214.     End If
    215.     Set oRsAccessEmail = Nothing
    216.  
    217. End Function

    continued....

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Here's the rest:

    VB Code:
    1. Private Function OpenOutlookEmail(ByVal oEmailEntryID As String, sType As String)
    2. 'PASS THE .ENTRYID AND THE .TYPE PROPERTY OF THE OUTLOOK ITEM
    3.     On Error GoTo No_Bugs
    4.    
    5.     Dim oOBJ As Object
    6.     Dim oItem As Object
    7.     Dim i As Integer
    8.     Dim bFound As Boolean
    9.    
    10.     'CHECK EACH ITEMS ENTRYID PROPERTY FOR A MATCH (.FIND NOT COMPATIBLE WITH .ENTRYID PROPERTY)
    11.     bFound = False
    12.     For i = 1 To oInbox.Items.Count
    13.         Set oItem = oInbox.Items(i)
    14.         If oItem.EntryID = oEmailEntryID Then
    15.             bFound = True
    16.             Exit For
    17.         Else
    18.             bFound = False
    19.         End If
    20.         Set oItem = Nothing
    21.     Next
    22.    
    23.     If bFound = True Then
    24.         Select Case CLng(sType)
    25.             Case olMail
    26.                 sType = "Email"
    27.             Case olMeetingRequest, olMeetingResponseNegative, olMeetingResponsePositive, olMeetingResponseTentative
    28.                 sType = "MeetingItem"
    29.             Case olDistributionList
    30.                 sType = "DistListItem"
    31.             Case Else
    32.                 sType = ""
    33.         End Select
    34.         Select Case sType
    35.             Case "Email", "MeetingItem", "DistListItem"
    36.                 Set oOBJ = oInbox.Items(i)
    37.                 If TypeName(oOBJ) <> "Nothing" Then
    38.                     oOBJ.Display 'THE USE CAN MAKE CHANGES AND SAVE THEM TO OUTLOOK
    39.                 Else
    40.                     MsgBox sType & " not found in Outlook!", vbOKOnly + vbExclamation
    41.                 End If
    42.             Case Else
    43.                 MsgBox "Invalid Outlook Item Type Passed!", vbOKOnly + vbCritical
    44.         End Select
    45.     Else
    46.         MsgBox "Item not found in Outlook!", vbOKOnly + vbInformation
    47.     End If
    48.     Exit Function
    49.    
    50. No_Bugs:
    51.  
    52.     MsgBox Err.Number & " = " & Err.Description, vbOKOnly + vbExclamation
    53.     Exit Function
    54.     Resume
    55. End Function
    56.  
    57. '''''' 3rd 3rd
    58.  
    59. Private Function Outlook_Tasks_2_Access()
    60. '   <GORS = ACCESS>
    61.     On Error GoTo No_Bugs
    62.  
    63.     Dim goRs As ADODB.Recordset
    64.    
    65.     Dim oTask As Outlook.TaskItem
    66.     Dim oTaskReqAccpt As Outlook.TaskRequestAcceptItem
    67.     Dim oTaskReqDcln As Outlook.TaskRequestDeclineItem
    68.     Dim oTaskReqItm As Outlook.TaskRequestItem
    69.     Dim oTaskReqUpd As Outlook.TaskRequestUpdateItem
    70.    
    71.     Dim vType As Variant
    72.    
    73.     Dim i As Integer
    74.     Dim ii As Integer
    75.     Dim iii As Integer
    76.    
    77.     Dim sAttachment As String
    78.     Dim sRecipients As String
    79.    
    80.     Dim sSQL As String
    81.    
    82.     Set goRs = New ADODB.Recordset
    83.    
    84.     sSQL = "SELECT * FROM [Tasks] WHERE 1=2;"
    85.     goRs.Open sSQL, CnnA, adOpenKeyset, adLockOptimistic, adCmdText
    86.    
    87.     prbProgress.Max = oTasks.Items.Count
    88.     i = 1
    89.     Do While i <= oTasks.Items.Count
    90.         DoEvents
    91.         Select Case oTasks.Items(i).Class
    92.             Case olTask
    93.                 vType = "Task"
    94.             Case olTaskRequestAccept
    95.                 vType = "TaskReqAccpt"
    96.             Case olTaskRequestDecline
    97.                 vType = "TaskReqDcln"
    98.             Case olTaskRequest
    99.                 vType = "TaskReqItm"
    100.             Case olTaskRequestUpdate
    101.                 vType = "TaskReqUpd"
    102.         End Select
    103.         If vType = "Task" Then 'ONLY TASK TYPES
    104.             Set oTask = oTasks.Items(i)
    105.             If FindOutlookTask(oTask.EntryID) = False Then
    106.                 'ADDED FOR TESTING ONLY SO YOU CAN SEE HOW TO PASS THE ITEMS.
    107.                 'TAKE OUT AND PLACE WHERE YOU ARE CALLING IT FROM
    108.                 'OTHERWISE IT WILL OPEN ALL EXPORTED TASKS
    109.                 Call OpenOutlookTask(oTask.EntryID, CStr(oTasks.Items(i).Class))
    110.                 goRs.AddNew
    111.                 goRs!To = oTask.Recipients.Item(0).Name
    112.                 sRecipients = ""
    113.                 For iii = 1 To oTask.Recipients.Count - 1
    114.                     sRecipients = sRecipients & oTask.Recipients.Item(iii).Name & "; "
    115.                 Next
    116.                 goRs!CC = sRecipients
    117.                 goRs!Subject = oTask.Subject
    118.                 goRs!Body = oTask.Body           'PLAIN TEXT BODY NOTES
    119.                 goRs!Importance = oTask.Importance
    120.                 goRs!StartDate = oTask.StartDate
    121.                 goRs!Class = oTask.Class 'TASK, TASKREQUESTACCEPT, TASKREQUESTDECLINE, ETC.
    122.                 goRs!ReceivedByName = oTask.ReceivedByName
    123.                 goRs!EntryID = oTask.EntryID
    124.                 If oTask.Attachments.Count > 1 Then
    125.                     'LOOP THROUGH ALL ATTACHMENTS SAVING TO DIRECTORY AND ENTERING FILENAME INTO FIELD
    126.                     For ii = 1 To oTask.Attachments.Count
    127.                         'DETERMINE ATTACHMENT CLASS TYPE ATTACHED, LINKED, EMBEDDED, OR OLE
    128.                         If oTask.Attachments.Item(ii).Type = olByValue Or oTask.Attachments.Item(ii).Type = olEmbeddeditem Then
    129.                             oTask.Attachments.Item(ii).SaveAsFile "C:\MyOutlookEmailExport\Attachments\" & oTask.Attachments.Item(ii).FileName
    130.                             sAttachment = sAttachment & "C:\MyOutlookEmailExport\Attachments\" & oTask.Attachments.Item(ii).FileName & vbNewLine
    131.                         End If
    132.                     Next
    133.                     goRs!Attachment = sAttachment
    134.                 Else
    135.                     goRs!Attachment = "None"
    136.                 End If
    137.                 'CONTINUE ON WITH OTHER FIELD YOU WANT
    138.                 '...
    139.                 goRs.Update
    140.             End If
    141.             Set oTask = Nothing
    142.         'MORE CODE GOES HERE FOLOWING SAME LOGIC
    143.         'ElseIf
    144.        
    145.         'ElseIf
    146.         'etc.
    147.         End If
    148.  
    149.  
    150. End Function
    151.  
    152. Private Function FindOutlookTask(ByVal oTaskEntryID As String) As Boolean
    153.  
    154.     Dim oRsAccessTask As ADODB.Recordset 'TASK IN ACCESS TO CHECK AGAINST
    155.    
    156.     Dim i As Integer
    157.    
    158.     Set oRsAccessTask = New ADODB.Recordset
    159.     oRsAccessTask.Open "SELECT EntryID FROM Tasks WHERE EntryID = '" & oTaskEntryID & "';", CnnA, adOpenKeyset, adLockReadOnly, adCmdText
    160.     If oRsAccessTask.BOF = True And oRsAccessTask.EOF = True Then
    161.         FindOutlookTask = False
    162.     Else
    163.         FindOutlookTask = True
    164.     End If
    165.     Set oRsAccessTask = Nothing
    166.  
    167. End Function
    168. Private Function OpenOutlookTask(ByVal oTaskEntryID As String, sType As String)
    169. 'PASS THE .ENTRYID AND THE .TYPE PROPERTY OF THE OUTLOOK ITEM
    170.     On Error GoTo No_Bugs
    171.    
    172.     Dim oOBJ As Object
    173.     Dim oItem As Object
    174.     Dim i As Integer
    175.     Dim bFound As Boolean
    176.    
    177.     'CHECK EACH ITEMS ENTRYID PROPERTY FOR A MATCH (.FIND NOT COMPATIBLE WITH .ENTRYID PROPERTY)
    178.     bFound = False
    179.     For i = 1 To oInbox.Items.Count
    180.         Set oItem = oTasks.Items(i)
    181.         If oItem.EntryID = oEmailEntryID Then
    182.             bFound = True
    183.             Exit For
    184.         Else
    185.             bFound = False
    186.         End If
    187.         Set oItem = Nothing
    188.     Next
    189.    
    190.     If bFound = True Then
    191.         Select Case CLng(sType)
    192.             Case olTask
    193.                 sType = "Task"
    194.             Case olTaskRequestAccept, olTaskRequestDecline, olTaskRequest, olTaskRequestUpdate
    195.                 sType = "TaskItem"
    196.             Case Else
    197.                 sType = ""
    198.         End Select
    199.         Select Case sType
    200.             Case "Task", "TaskItem"
    201.                 Set oOBJ = oTasks.Items(i)
    202.                 If TypeName(oOBJ) <> "Nothing" Then
    203.                     oOBJ.Display 'THE USE CAN MAKE CHANGES AND SAVE THEM TO OUTLOOK
    204.                 Else
    205.                     MsgBox sType & " not found in Outlook!", vbOKOnly + vbExclamation
    206.                 End If
    207.             Case Else
    208.                 MsgBox "Invalid Outlook Item Type Passed!", vbOKOnly + vbCritical
    209.         End Select
    210.     Else
    211.         MsgBox "Item not found in Outlook!", vbOKOnly + vbInformation
    212.     End If
    213.     Exit Function
    214.    
    215. No_Bugs:
    216.  
    217.     MsgBox Err.Number & " = " & Err.Description, vbOKOnly + vbExclamation
    218.     Exit Function
    219.     Resume
    220. End Function

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    You dont need the tasks code since we are only going to be dealing with the inbox.

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    You know what, I think it would be easier to just start fresh. Also most of my code is for dealingwith the tasks folder too.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    haha, i'm really sorry for the trouble, robdog. I guess the reason I was trying to modify your old code is because I learn really well from example and that was absolutely the best example I could find anywhere!!

    Starting from fresh sounds like a great way to learn too!!!

  22. #22
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Ok, to start, my code example was using VB6 to interact with both Access and Outlook. If this is a possibility then we can reuse most of the code but if not then we will use parts of it placed in both Outlook and Access.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    I can't use VB6 because VB6 is not loaded onto my company's OS build. I work for a corporation and they have their own OS build with apps, etc. Office is included, but VB6 is not.

  24. #24
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Ok, no problem. Which version of Outlook and Access are we dealing with? All the same versions on all systems?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    From Help -> About...

    Microsoft Visual Basic 6.3
    Version 9972
    VBA: Retail 6.4.9972
    Forms3: 11.0.6254

    Yes, all the versions are the same.
    Last edited by RiceRocket; Apr 3rd, 2006 at 01:30 PM.

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    That relates to Office 2003 but are you all updated with SP2?

    Also, how does the import into Access need to occur? Do it from an open email and pull down a menu item to export it or select the email and then pull down a menu item from that mail Outlook interface. The second is easier.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Yes, I do realize the second is easier and I already have the code you gave me a month ago or so that adds a toolbar button to the inspector window (thanks!!!). The button is under Tools -> Add to the AR Tracker... However, it would be *nice to have* the option to allow the user to have the email open. But this is not as important as getting the whole thing to work, which is my number 1 priority. After everything works, then I will see what i can do about adding a button to start this function from an opened email.

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Sorry for not answering your first question... yes SP2 and all... IT pushes all updates immediately.

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Crap... actually it seems they aren't pushing Office updates... here are the versions for Outlook and Access:

    Outlook: 11.6359.6360 SP1
    Access: 11.6355.6360 SP1

    Sorry about that!

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    If there is something about SP2 that is easier to use, then I can make sure that everyone who uses this tracker tool will need to update the SP2. That shouldn't be a problem, so do whatever is easier for you.

  31. #31
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    No issues between sp1 and sp2 but just needing to know how to handle the references. Since we are all on the same version and latest one we can early bind but if there is ever an upgrade then all you have to do is change the reference to the new version. Early binding is easier to work with as it gives you intellisense popups.

    If your saying that you have my code for the inspector window then that is an opened email. the close email will be an explorer window. Where are you at with this then?


    Ps, sorry for the delays but I am multitasking on a project.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  32. #32

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    No worries on the delay, I know you're busy! Here is the code I have in ThisOutlookSession (this works for the explorer window)...

    VB Code:
    1. Option Explicit
    2. 'Behind ThisOutlookSession
    3. Public WithEvents oMnuSaveAs As Office.CommandBarButton
    4.  
    5. Private Sub SyncMnuSaveAsButton(btn As Office.CommandBarButton)
    6.     Set oMnuSaveAs = btn
    7.     If btn Is Nothing Then
    8.         MsgBox "Sync. of '" & btn.Caption & "' button event failed!", vbCritical + vbOKOnly
    9.     End If
    10. End Sub
    11.  
    12. Private Sub Application_MAPILogonComplete()
    13.    
    14.     Dim oCBmnuTools As Office.CommandBarPopup
    15.     Dim oCBmnuSaveMe As Office.CommandBarButton
    16.    
    17.     '<ADD A MENU ITEM>
    18.     Set oCBmnuTools = Application.ActiveExplorer.CommandBars("Menu Bar").Controls("&Tools")
    19.     Set oCBmnuSaveMe = Application.ActiveExplorer.CommandBars("Menu Bar").FindControl(msoControlButton, 1, "888", True, True)
    20.     If TypeName(oCBmnuSaveMe) = "Nothing" Then
    21.         Set oCBmnuSaveMe = oCBmnuTools.Controls.Add(msoControlButton, 1, "888", , True)
    22.     End If
    23.     With oCBmnuSaveMe
    24.         .BeginGroup = True
    25.         .Caption = "Add to AR Tracker..."
    26.         .Enabled = True
    27.         .Style = msoControlCustom
    28.         .Tag = "888"
    29.         .Visible = True
    30.     End With
    31.     Call SyncMnuSaveAsButton(oCBmnuSaveMe)
    32.     '</ADD A MENU ITEM>
    33. End Sub
    34.  
    35. Private Sub oMnuSaveAs_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
    36. ''' Anything in this sub can be changed!! '''
    37.     'Dim myExcel As Object
    38.     MsgBox "booya!"
    39.     'Set myExcel = CreateObject(Excel.Application)
    40.     arInfo.Show
    41. End Sub

    If adding a button to an opened email is easier than this, then I would love for you to share how you did it, otherwise if it is more complicated, we can come back to that later, if needed.

  33. #33

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Hey RobDog...

    I've been working on some code just to get my head in the game as to how to connect the Access and Outlook objects (which really isn't that bad with VBA). I know this is probably horrible code (remember I just started learning Outlook/Excel VBA objects/methods) and I know it's not much, but at least its a start... I'm also trying to show you that I'm not relying on you to write code for me (although it would be nice! ). Here it is:

    VB Code:
    1. Private Sub test()
    2.     Dim ACobj As Access.Application
    3.     Dim txtDBstring As String
    4.     'Dim myRS As Access.Control
    5.     'Dim myfolder As Outlook.MAPIFolder
    6.     Dim myExplorers As Outlook.Explorer
    7.     Dim myExpSel    As Outlook.Selection
    8.     Dim myMailItem As Outlook.MailItem
    9.     Dim myForm As Access.Form
    10.    
    11.     txtDBstring = "C:/Documents and Settings/edmastro.AMR/My Documents/Issue database.mdb"
    12.    
    13.     Set ACobj = GetObject("C:\Documents and Settings\edmastro.AMR\My Documents\Issues database.mdb", "Access.Application")
    14.     'Set myfolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    15.     Set myExplorers = Application.ActiveExplorer
    16.     Set myExpSel = myExplorers.Selection
    17.     Set myMailItem = CreateItem(olMailItem)
    18.     Set myForm = Access.Forms("Issues")
    19.    
    20.     ACobj.DoCmd.OpenForm ("Issues")
    21.     ACobj.DoCmd.GoToRecord acDataForm, "Issues", acNewRec
    22.    
    23.     'myForm!Comments = "Booya!"
    24.    
    25.     If Not myExpSel.Item(1) Is Nothing Then
    26.         myForm!Comments = myExpSel.Item(1).Body
    27.     End If
    28.    
    29.     'If Application.ActiveExplorer.CurrentItem = "MailItem" Then MsgBox "mailitem"
    30.    
    31.     Set ACobj = Nothing
    32.     Set myRS = Nothing
    33.     Set myfolder = Nothing
    34.     Set myExplorers = Nothing
    35.     Set myExpSel = Nothing
    36.     Set myMailItem = Nothing
    37.     Set myForm = Nothing
    38. End Sub

    So where I'm stuck at right now is how to reference an Access form (myForm) and its controls from Outlook. I tried to access a Comments textbox in myFrom using "myForm!Comments" but that doesn't work. I want to set the comments textbox equal to the contents of the email (.body). Any ideas on how to reference the form and its controls from Outlook?

  34. #34
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Import E-Mails from Outlook to Access, and read them from Access?

    Try opening the form first and then setting your object variable to the item in the forms collection.
    VB Code:
    1. ACobj.DoCmd.OpenForm ("Issues")
    2. Set myForm = Access.Forms("Issues")
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width