To retrieve attachements from Emails into my database i use a procedure of wich a part is given below.
Most of tHe time this code works fine, but now and then, for reasons i can't figure out i get a errormessage telling me that there are type mismatched. That happens when the execution of the code reach the line marked with (*). If i replace the codeline "On error GoTo Errorhandler " by "On Error Resume next", neglecting the error,the execution of the code works allwright!
What's going on ?
Public Sub SaveAttachments()
On Error GoTo ErrorHandler
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim MoveFldr2 As MAPIFolder
Dim MoveFldr3 As MAPIFolder
Dim olMi As mailitem
Dim olAtt As Outlook.attachment
Dim MyPath1 As String
Dim MyPath2 As String
Dim I As Long
Dim Aantal As Integer
On Error Goto ErrorHandler
Set olApp = GetObject(, "Outlook.Application")
If Err = 429 Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo ErrorHandler
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set MoveToFldr = Fldr.Folders("Special")
MyPath1 = "C:\DW\Isabelle\"
MyPath2 = "C:\DW\Bart\"
(*) For I = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(I)
If InStr(1, olMi.Subject, "Geboekte orders van agent Bart") > 0 Then
MsgBox " Er werd een Email afkomstig van Bart gevonden"
For Each olAtt In olMi.Attachments
Bart = True
If olAtt.FileName = "Ordersverzenden_be.accdb" Then
olAtt.SaveAsFile MyPath2 & olAtt.FileName 'de bijlage wordt opgeslagen in c:\dw\Bart
End If
Next olAtt
olMi.Move MoveToFldr
...
...
Most of tHe time this code works fine, but now and then, for reasons i can't figure out i get a errormessage telling me that there are type mismatched. That happens when the execution of the code reach the line marked with (*). If i replace the codeline "On error GoTo Errorhandler " by "On Error Resume next", neglecting the error,the execution of the code works allwright!
What's going on ?
Public Sub SaveAttachments()
On Error GoTo ErrorHandler
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim MoveFldr2 As MAPIFolder
Dim MoveFldr3 As MAPIFolder
Dim olMi As mailitem
Dim olAtt As Outlook.attachment
Dim MyPath1 As String
Dim MyPath2 As String
Dim I As Long
Dim Aantal As Integer
On Error Goto ErrorHandler
Set olApp = GetObject(, "Outlook.Application")
If Err = 429 Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo ErrorHandler
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set MoveToFldr = Fldr.Folders("Special")
MyPath1 = "C:\DW\Isabelle\"
MyPath2 = "C:\DW\Bart\"
(*) For I = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(I)
If InStr(1, olMi.Subject, "Geboekte orders van agent Bart") > 0 Then
MsgBox " Er werd een Email afkomstig van Bart gevonden"
For Each olAtt In olMi.Attachments
Bart = True
If olAtt.FileName = "Ordersverzenden_be.accdb" Then
olAtt.SaveAsFile MyPath2 & olAtt.FileName 'de bijlage wordt opgeslagen in c:\dw\Bart
End If
Next olAtt
olMi.Move MoveToFldr
...
...