-
Jul 31st, 2015, 09:28 AM
#41
Re: Outlook - print coressponding email
Sorry, thought I read first that you didn't know what the error was.
Which line gives you that?
-
Jul 31st, 2015, 09:30 AM
#42
Thread Starter
Junior Member
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
-
Jul 31st, 2015, 09:51 AM
#43
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.
-
Jul 31st, 2015, 09:56 AM
#44
Thread Starter
Junior Member
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
-
Jul 31st, 2015, 10:06 AM
#45
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
-
Jul 31st, 2015, 10:10 AM
#46
Thread Starter
Junior Member
Re: Outlook - print coressponding email
I put error handlers there and let you know the results already.
-
Jul 31st, 2015, 10:25 AM
#47
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?
-
Jul 31st, 2015, 10:26 AM
#48
Re: Outlook - print coressponding email
(duplicate - not sure why)
Last edited by vbfbryce; Jul 31st, 2015 at 10:29 AM.
-
Jul 31st, 2015, 10:31 AM
#49
Thread Starter
Junior Member
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
-
Jul 31st, 2015, 10:32 AM
#50
Thread Starter
Junior Member
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
-
Jul 31st, 2015, 10:50 AM
#51
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.
-
Jul 31st, 2015, 11:09 AM
#52
Thread Starter
Junior Member
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
-
Jul 31st, 2015, 11:39 AM
#53
Re: Outlook - print coressponding email
I'd suggest you post your entire code as it now stands.
-
Jul 31st, 2015, 10:49 PM
#54
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|