Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191

    Grab Mail on another PC


    Hi Guy's. i have got a new PC for home use and when i use my Grab Mail function, it doesn't seem to want to play, below is what code i have and what is happening, can you great guy's help ?

    I have got the mail i want to grab active on the taskbar

    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
    Click image for larger version. 

Name:	Snip1.PNG 
Views:	17 
Size:	3.7 KB 
ID:	45372

    Here are the reference libraries i have got set on my machine, i also believe my other machines are office 365 2016 and this new PC is office 365 2019, does that make a difference ?

    Click image for larger version. 

Name:	Snip2.PNG 
Views:	17 
Size:	16.5 KB 
ID:	45373

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    Shouldn’t there be a dim before wordapp and be on a separate line?

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Walk through the code line by line and inspect what you have.
    I'd expect you'd need an Outlook object?

    You do not even say on what line you get the error?
    Last edited by Welshgasman; 05-30-2021 at 08:11 AM.
    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

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    Hi Guy's there is a Dim before wordapp, when i paste the code on here, it appears to put it on the same line but it's

    Dim WordApp as Word.Application

    The line that debugs is:

    If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then

    Kind REgards

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Activeexplorer is an outlook item, yet you have no outlook object.?
    How did this work on the other pc?

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    Thank you welshgasman, i must have an object on the event procedure sub to declare an outlook object!

    I suppose my best question is can my initial function GrabMail read the mail body and paste onto Forms!frmMainMenu!txtMailMessage ?

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    I have tried adding outlook.mail item and still no joy

    Code:
    Public Function GrabMail() As String
    
    Dim WordApp As Word.Application
    
    Dim MailBody As Outlook.MailItem changed this to Outlook.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

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    I posted code in another thread of yours about attachments didn't I?
    That has the ActiveExplorer property, but also refers to the Outlook object, so Yes, I would say you need Outlook and then it's ActiveExplorer property.

    Look at that code.

    Yes, if you ever get to the correct email, you can copy it. I would have thought it would be something like MailBody.Text (or body/htmlbody) though?
    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

  9. #9
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    Active x cant create object, i now have this error in the below code, is it that i haven't got the option for active x and it's struggling to create an object ??

    Code:
    Dim app As ObjectDim SearchString As String, myOpt As String, mySearch As String
    
    
    myOpt = InputBox("Enter What You Want To Search ?" & vbNewLine & vbNewLine & _
    Chr(149) & " 1 " & Chr(149) & " Full Call Diary" & vbNewLine & vbNewLine & _
    Chr(149) & " 2 " & Chr(149) & " Callers Name" & vbNewLine & vbNewLine & _
    Chr(149) & " 3 " & Chr(149) & " Callers Location (Town)" & vbNewLine & vbNewLine & _
    Chr(149) & " 4 " & Chr(149) & " Callers Location (PostCode)" & vbNewLine & vbNewLine & _
    Chr(149) & " 5 " & Chr(149) & " Phone Number", "ENTER YOUR SEARCH OPTION")
    Select Case myOpt
    Case 1
    myString = "Call Diary"
    Case 2
    mySearch = InputBox("Enter Callers Name ?", "CALLERS NAME")
    Case 3
    mySearch = InputBox("Enter Callers Location ?", "CALLERS NAME")
    Case 4
    mySearch = InputBox("Enter Callers Postcode ?", "CALLERS POSTCODE")
    Case 5
    mySearch = InputBox("Enter Callers Phone Number ?", "CALLERS NUMBER")
    End Select
    
    
    Set app = GetObject(, "Outlook.Application") This debugs so am thinking its related to creating active x objects ???
    On Error GoTo 0
    If app Is Nothing Then
    Set app = CreateObject("Outlook.Application")
    app.Explorers.Add app.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    app.Explorers(1).Activate
    End If
    SearchString = mySearch
    app.ActiveExplorer.Search SearchString, olSearchScopeAllFolders
    Set app = Nothing
    DoCmd.RunCommand acCmdAppMinimize

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    I have no idea where you are getting your code ideas from?

    I have this in a sub to send emails from Access

    Code:
     ' See if Outlook is open, otherwise open it
        'If fIsOutlookRunning = False Then
        Set objOutlook = CreateObject("Outlook.Application")
        'Call OpenOutlook
        'Pause (5)
        ' Else
        'Set objOutlook = GetObject(, "Outlook.Application")
        'End If
    That works even when I have outlook open (which I normally would have) and I set it to Nothing at the end. You can see that I initially was trying to do the same as you, then found out no need (for me at least)?

    Please amend your code you paste to truly reflect what you have, never mind what the side does to it.?
    Not
    Dim app As ObjectDim SearchString As String, myOpt As String, mySearch As String
    Code:
    Dim app As Object
    Dim SearchString As String, myOpt As String, mySearch As String
    You already have outlook as a reference, so why not use it's name? called Early Binding, unless you need Late Binding?
    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

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Hi Dave,
    Can you please try this modified function:
    Code:
    Public Function GrabMail() As String
    
    
    Dim WordApp As Word.Application
    
    
    Dim MailBody As Outlook.MailItem changed this to Outlook.MailItem
    dim outApp as Outlook.Application
    
    
    Set outApp = CreateObject("Outlook.Application")
    
    
    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 = MailBody
    End If
    End Function
    Also in your searching code remove the GetObject part and just leave the CreateObject (it reuses the existing Outlook instance is already running).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Just discovered this piece of code I had from somewhere, this is only part of it, but should make things clearer
    Code:
        Set olApp = VBA.GetObject(, "Outlook.Application")  'Assumes Outlook is open else err 429
        Err.Clear
        If olApp Is Nothing Then GoTo ExitRoutine   'Outlook needs to be open!
    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

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    Hi Vlad, it still debugs on If TypeName(outApp.ActiveExplorer.Selection.Item(1)) = "MailItem" Then

    RunTime Error 91 Object variable or with variable not set!

    Please forgive me if i am missing something

    This is copying your modified function

    Thanks again, i will look at your other option and welshgasman suggestion

    Thank you

  15. #15
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    Hi Guy's i have very similar code on my laptop and it works ok on there!!!!

    I have found the following code on the internet, so this does actually copy and paste to Forms!frmMainMenu!txtMailMessage but it copies the code in the function, I now think it has something to do with the mail that is open

    I am using 365 outlook but my reading view is totally different in this version, is this some thing to do with it ???

    Code that will paste the Function into mailmessage txt box

    Code:
    Function GetCurrentItem() As Object Dim objApp As Outlook.Application 
    Set objApp = CreateObject("Outlook.Application") 
    On Error Resume Next 
    Select Case TypeName(objApp.ActiveWindow) 
    Case "Explorer" 
    Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1) 
    Case "Inspector" 
    Set GetCurrentItem = objApp.ActiveInspector.CurrentItem 
    Case Else
    End Select 
    Set objApp = Nothing 
    End Function

Page 1 of 2 12 LastLast
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