Page 2 of 2 FirstFirst 12
Results 41 to 54 of 54

Thread: Outlook - print coressponding email

  1. #41
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Outlook - print coressponding email

    Sorry, thought I read first that you didn't know what the error was.

    Which line gives you that?

  2. #42

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    29

    Re: Outlook - print coressponding email

    I'm not sure but if I move the errorhandler before the "for each" bit it still gives the same error

  3. #43
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Outlook - print coressponding email

    For testing purposes, you can put an error handler in front of each line, something like:

    Code:
    Sub errHandle()
        Dim pos As Integer
        Dim invNum As Integer
        
        On Error Resume Next
        pos = InStr("some text then Order Number: 123", "Order Number:") + 10
        If Err.Number > 0 Then
            MsgBox Err.Description
            Err.Clear
        End If
        
        On Error Resume Next
        invNum = Mid("some text with order number etc", pos)
        If Err.Number > 0 Then
            MsgBox Err.Description
            Err.Clear
        End If
        
        'etc.
    End Sub
    So you can figure out which line or lines generate errors.

  4. #44

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    29

    Re: Outlook - print coressponding email

    I just got two errors the same as mentioned before, I used your technique on the code before the for each and where the inbox is set

  5. #45
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Outlook - print coressponding email

    From 22:

    Code:
    Dim olItem As Outlook.MailItem
        Dim sText As String
        Dim oFldr As Outlook.MAPIFolder 'dim for identifying the inbox
        Dim oNs As Outlook.NameSpace
        
        'MsgBox ("Test") This message box works
        
       'add err handle here **************
        pos = InStr(olItem.body, "Order Number: ") + 10
    
    
        'add err handle here *************
        invnum = Val(Mid(olItem.body, pos))
        
        'add err handle here *************
        MsgBox (CStr(invnum))
    
        'any error(s) in the above 3 spots? ****************
    
    
        MsgBox (invnum)
        
        'set inbox as folder to check
         Set oFldr = Application.NameSpace("mapi").GetDefaultFolder(olFolderInbox)
    
        For Each olItem In oFldr
        
            With olItem
            
                If InStr(.body, "Order Number: " & invnum) > 0 Then
                
                    'code to do with each email goes here
                    olItem.PrintOut
                    
                    
                    Exit For    ' matched, don't continue

  6. #46

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    29

    Re: Outlook - print coressponding email

    I put error handlers there and let you know the results already.

  7. #47
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Outlook - print coressponding email

    So you're saying the errors don't happen until after this?

    Code:
    MsgBox (CStr(invnum))
    Then you should have a message box appear. Do you?

  8. #48
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Outlook - print coressponding email

    (duplicate - not sure why)
    Last edited by vbfbryce; Jul 31st, 2015 at 10:29 AM.

  9. #49

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    29

    Re: Outlook - print coressponding email

    What I get is

    Error - Object variable or With block variable not set
    Error - Object variable or With block variable not set
    Blank message box (I presume this is where the invnum variable should be written
    Message Box - Test

  10. #50

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    29

    Re: Outlook - print coressponding email

    What I get is

    Error - Object variable or With block variable not set
    Error - Object variable or With block variable not set
    Blank message box (I presume this is where the invnum variable should be written
    Message Box - Test

  11. #51
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Outlook - print coressponding email

    From 22:

    You can't do this:

    Code:
    pos = InStr(olItem.body, "Order Number: ") + 10
    before this:

    Code:
    For Each olItem In oFldr
    You haven't yet set the object variable (olItem) in the "pos =" line.

  12. #52

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    29

    Re: Outlook - print coressponding email

    I've tried putting the pos line up to the "MsgBox (invnum & "Test")" line with its error handling after the for each loop, but before the "With" part.

    No errors are coming up, but also the message box that should appear when the email is found isn't showing, code below.

    Code:
    With olItem
            
                If InStr(.body, "Order Number: " & invnum) > 0 Then
                
                    'code to do with each email goes here
                    MsgBox "Testy"
                    
                    
                    Exit For    ' matched, don't continue
                    
                Else
                    
                End If
            
            End With

  13. #53
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Outlook - print coressponding email

    I'd suggest you post your entire code as it now stands.

  14. #54
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Outlook - print coressponding email

    you still did not fix the error, as i suggested in as in post #23

    you try to read a property of an uninstanciated object, which crashes the procedure
    even if you step through it will still crash without warning
    the error message, you have now told us you get, is specific to this type of error, if you had posted the error message earlier it would have also helped us to help you

    olitem is not created until a later point, you first need to get the order number from the paypal email

    regardless of whether the correct order number is returned from the parse, a messagebox would still show, with or without some content

    maybe if you used meaningful names for your variables it would help
    Code:
    Sub paypalActions(paypalMail As MailItem)
    
        Dim olItem As Outlook.MailItem
        Dim sText As String
        Dim oFldr As Outlook.MAPIFolder 'dim for identifying the inbox
        Dim oNs As Outlook.NameSpace
        
        'MsgBox ("Test") This message box works
        
        pos = InStr(paypalMail.body, "Order Number: ") + 10
        invnum = Val(Mid(olItem.body, pos))
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Page 2 of 2 FirstFirst 12

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