Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling Outlook from Access

Status
Not open for further replies.

Ratman11

MIS
Apr 13, 2005
23
0
0
GB
Hi
I get the following error on the highlighted line of code...trying to run this to delete certain items out of my sent items folder after running some batch reports. Running this on access 97

The error is:
Run Time Error 13 'Type Mismatch'
I thought it might be because olMail hasn't been Set, but i cannot work out what to set it as...

Any clues?

Code:
Public Function test()

Dim OlApp As Outlook.Application
Dim OlMapi As Outlook.NameSpace
Dim OlFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Dim OlItems As Outlook.Items
'Dim OlAtch As Outlook.Attachment

Set OlApp = New Outlook.Application
Set OlMapi = OlApp.GetNamespace("MAPI")
Set OlFolder = OlMapi.GetDefaultFolder(olFolderSentMail)
Set OlItems = OlFolder.Items

[highlight]For Each olMail In OlItems[/highlight]
'If olMail.UnRead = False Then
If olMail.subject Like "*call centre data*" Then
'If LCase(OlMail.Subject) Like "*call center data*" Then
'If olMail.Attachments.Count > 0 Then
'For Each OlAtch In olMail.Attachments
'OlAtch.SaveAsFile "C:\FolderName\" & OlAtch.FileName
'Next OlAtch
'OlMail.Move OlMapi.GetDefaultFolder(olFolderDeletedItems)
olMail.Delete
'End If
'End If
End If
Next olMail
End Function
 
Try to replace this:
Dim olMail As Outlook.MailItem
By this:
Dim olMail

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi
That didn't work, but managed to fix it by replacing it with:
Dim olMail as Variant

it was because the sent-items folder contains more than just mail items (appointments, calendar tasks etc.).

It all works now!
 
Ratman11, Dim olMail as Variant should be the same as I suggested Dim olMail
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top