stephen1990
New member
- Local time
- Today, 08:55
- Joined
- Oct 7, 2012
- Messages
- 4
Hi,
I have a problem that I can't find a solution for anywhere.
I have a form that on load populates the form with a contacts details take from outlook, it also has 3 list boxes on it 2 of which show emails sent to and received from the selected contact, and the 3rd is meant to show any appointments where the contacts was a recipient/attendee.
the code should loop through each appointment and then loop through the recipients in each appointment and if the contact is included in the appointment it should add the details to the list box. however when the code runs i get and type mis match error.
the code is:
Private Sub Form_Load()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objConatactFolder As Outlook.MAPIFolder
Dim objAppFolder, objMailFolder As Outlook.MAPIFolder
Dim objItems, objAppItems, objMailItems As Outlook.Items
Dim objCont As Outlook.ContactItem
Dim objApp As Outlook.AppointmentItem
Dim objMail As Outlook.MailItem
Dim Args As Variant
Dim strName, strMail, srtTxtStart, strTxtDate, strTxtEnd As String
Args = Split(Me.OpenArgs, ";")
strName = Args(0)
strMail = Args(1)
Set objOL = New Outlook.Application
Set objNS = objOL.GetNamespace("MAPI")
Set objContactFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactFolder.Items.Restrict("[Full Name] = '" & strName & "' and [Mail1Address] = '" & strMail & "'")
For Each objCont In objItems
With objCont
txtFirst = .FirstName
txtLast = .LastName
txtComp = .CompanyName
txtJob = .JobTitle
txtMail = .Mail1Address
txtWork = .BusinessTelephoneNumber
txtMob = .MobileTelephoneNumber
End With
Next
Dim strFull As String
strFull = txtFirst & " " & txtLast
Set objAppFolder = objNS.GetDefaultFolder(olFolderCalendar)
Set objAppItems = objAppFolder.Items
Dim x, j As Integer
/*****This is the section of code that doesnt work
' For Each objApp In objAppItems
' With objApp
' x = .Recipients.Count
' j = 0
' If x > 0 Then
' j = j + 1
' Do Until j = x
' If .Recipients.Item(j).Address = txtMail.Value Then
' lstApps.AddItem (.Start & ";" & .Subject)
' j = j + 1
' Else
' j = j + 1
' End If
'Loop
' End If
'End With
'Next
/****************************
Set objMailFolder = objNS.GetDefaultFolder(olFolderInbox)
Set objMailItems = objMailFolder.Items.Restrict("[From] = '" & strFull & "' or [From] = '" & txtMail & "'")
For Each objMail In objMailItems
With objMail
lstMail.AddItem (.SentOn & ";" & .Subject)
End With
Next
Set objMailFolder = objNS.GetDefaultFolder(olFolderSentMail)
Set objMailItems = objMailFolder.Items.Restrict("[To] = '" & strFull & "' or [To] = '" & txtMail & "'")
For Each objMail In objMailItems
With objMail
lstMailTo.AddItem (.SentOn & ";" & .Subject)
End With
Next
End Sub
any suggestions would be much appreciated
Many Thanks
Stephen
p.s i am using OUtlook & Access 2010
I have a problem that I can't find a solution for anywhere.
I have a form that on load populates the form with a contacts details take from outlook, it also has 3 list boxes on it 2 of which show emails sent to and received from the selected contact, and the 3rd is meant to show any appointments where the contacts was a recipient/attendee.
the code should loop through each appointment and then loop through the recipients in each appointment and if the contact is included in the appointment it should add the details to the list box. however when the code runs i get and type mis match error.
the code is:
Private Sub Form_Load()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objConatactFolder As Outlook.MAPIFolder
Dim objAppFolder, objMailFolder As Outlook.MAPIFolder
Dim objItems, objAppItems, objMailItems As Outlook.Items
Dim objCont As Outlook.ContactItem
Dim objApp As Outlook.AppointmentItem
Dim objMail As Outlook.MailItem
Dim Args As Variant
Dim strName, strMail, srtTxtStart, strTxtDate, strTxtEnd As String
Args = Split(Me.OpenArgs, ";")
strName = Args(0)
strMail = Args(1)
Set objOL = New Outlook.Application
Set objNS = objOL.GetNamespace("MAPI")
Set objContactFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactFolder.Items.Restrict("[Full Name] = '" & strName & "' and [Mail1Address] = '" & strMail & "'")
For Each objCont In objItems
With objCont
txtFirst = .FirstName
txtLast = .LastName
txtComp = .CompanyName
txtJob = .JobTitle
txtMail = .Mail1Address
txtWork = .BusinessTelephoneNumber
txtMob = .MobileTelephoneNumber
End With
Next
Dim strFull As String
strFull = txtFirst & " " & txtLast
Set objAppFolder = objNS.GetDefaultFolder(olFolderCalendar)
Set objAppItems = objAppFolder.Items
Dim x, j As Integer
/*****This is the section of code that doesnt work
' For Each objApp In objAppItems
' With objApp
' x = .Recipients.Count
' j = 0
' If x > 0 Then
' j = j + 1
' Do Until j = x
' If .Recipients.Item(j).Address = txtMail.Value Then
' lstApps.AddItem (.Start & ";" & .Subject)
' j = j + 1
' Else
' j = j + 1
' End If
'Loop
' End If
'End With
'Next
/****************************
Set objMailFolder = objNS.GetDefaultFolder(olFolderInbox)
Set objMailItems = objMailFolder.Items.Restrict("[From] = '" & strFull & "' or [From] = '" & txtMail & "'")
For Each objMail In objMailItems
With objMail
lstMail.AddItem (.SentOn & ";" & .Subject)
End With
Next
Set objMailFolder = objNS.GetDefaultFolder(olFolderSentMail)
Set objMailItems = objMailFolder.Items.Restrict("[To] = '" & strFull & "' or [To] = '" & txtMail & "'")
For Each objMail In objMailItems
With objMail
lstMailTo.AddItem (.SentOn & ";" & .Subject)
End With
Next
End Sub
any suggestions would be much appreciated
Many Thanks
Stephen
p.s i am using OUtlook & Access 2010