Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368

    I have just used my VNC to log into work and this is my grab mail function which is exactly the same and works great! do you guys think there is a setting in outlook ???

    Code:
    Public Function GrabMail() As StringDim WordApp As Word.Application
    Dim MailBody As MailItem
    
    
    If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
    Set MailBody = ActiveExplorer.Selection.Item(1)
    MailBody.GetInspector().WordEditor.Range.FormattedText.Copy
    Forms!frmMainMenu!txtMailMessage = MailBody
    End If
    
    
    End Function

  2. #17
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    Nothing like you are writing now? Plus you use CreateObject?
    You also ignore any errors?

  3. #18
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Thank you welshgasman but if it works on my work DB shouldn't it work on home one unless there is an outlook issue ? you will know more than me but im guessing logically

  4. #19
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    This is my command button to call grab mail so does this clarify where i am going wrong ?

    Code:
    Dim myApp As ObjectDim ol As Outlook.Application
    
    
    
    
    Set ol = CreateObject("Outlook.Application")
    
    
    
    
    
    
    Me.txtMailMessage = ""
    GrabMail
    
    
    Me.txtMailMessage.SetFocus
    DoCmd.RunCommand acCmdPaste

  5. #20
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    So you create the outlook object there, but I do not understand how that can be seen in grabmail. This is beyond me😔
    You also appear to paste the result AND set it in the function?

  6. #21
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Have a look at the attached sample it works for me...
    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #22
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Hi Vlad, thank you, so soon as i open your database12 it auto comes up the runtime error 91 again, does this tell us all its not the VBA ?

  8. #23
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Do you have Outlook open with a message open when you open the db?
    The error I believe is caused by the fact that you do not have an Outlook explorer window open with an email message loaded.
    This updated function catches that and displays a message, modify as you wish:
    Code:
    Public Function GrabMail() As String
    
    
    
    
    Dim MailBody As Outlook.MailItem  ' changed this to Outlook.MailItem
    Dim outApp As Outlook.Application
    Dim oExplorer As Outlook.Explorer
    
    
    Set outApp = CreateObject("Outlook.Application")
    
    
    Set oExplorer = outApp.ActiveExplorer
    If oExplorer Is Nothing Then
        MsgBox "No Outlook explorer open!", vbCritical, "No Outlook Explorer"
        Exit Function
    Else
        If TypeName(outApp.ActiveExplorer.Selection.Item(1)) = "MailItem" Then
            Set MailBody = outApp.ActiveExplorer.Selection.Item(1)
            MailBody.GetInspector().WordEditor.Range.FormattedText.Copy
            Forms!frmMainMenu!txtMailMessage.SetFocus  ' = MailBody
            'Debug.Print MailBody.GetInspector().WordEditor.Range.FormattedText
            DoCmd.RunCommand acCmdPaste
            
        End If
    End If
    End Function
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #24
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Cheers Vlad, you have cracked it, i think in one of my posts i mentioned i appear to have a different reading pane, i don't think it's outlook, will look into thtar, i wondered why it would work on other machines but not this new one!!

    I will change my email settings and defaults etc, thank you

    Click image for larger version. 

Name:	Snip3.PNG 
Views:	12 
Size:	2.5 KB 
ID:	45380

  10. #25
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Cheers Vlad, made the adjustments to default apps etc, all works good

    thank you welshgasman also for your input

    Solved

  11. #26
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    TBH I do not know how your code even works, due to the outlook object in one sub and it's properties in another?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #27
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Hi welshgasman, I have changed it now so the outlook object is in the function, the only event on the button now is GrabData

    I am now going to find your post about saving attachments to a folder as thats my next move

  13. #28
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Glad to hear you got it working, good luck with your project.
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-14-2015, 06:38 AM
  2. Replies: 2
    Last Post: 12-13-2013, 03:13 PM
  3. Replies: 1
    Last Post: 09-14-2012, 10:27 AM
  4. Grab first characters from field
    By sau3-access in forum Access
    Replies: 1
    Last Post: 10-04-2011, 10:40 AM
  5. Replies: 11
    Last Post: 09-12-2011, 11:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums