|
-
Aug 13th, 2007, 07:41 AM
#1
Thread Starter
Hyperactive Member
Create Contact in Folder/Delete Contact in Folder
Hey, awhile ago I posted here asking for help with outlook 2003 and my problems were resolved...however when I try working with outlook 2000...my code breaks. I have the following code for just adding a contact to outlook:
Code:
Dim ol As Outlook.Application
Dim ns As Outlook.NameSpace
Dim fl As Outlook.Folders
Dim itmContact As Outlook.ContactItem
' grab Outlook
Set ol = New Outlook.Application
' get MAPI reference
Set ns = ol.GetNamespace("MAPI")
' Create new Contact item
Set itmContact = ol.CreateItem(olContactItem)
' Setup Contact information...
With itmContact
.FullName = "James Smith"
.Anniversary = "09/15/1997"
' saving b-day info creates info in the calendar
.Birthday = "9/15/1975"
.CompanyName = "Microsoft"
.HomeTelephoneNumber = "704-555-8888"
.Email1Address = "[email protected]"
.JobTitle = "Developer"
.HomeAddress = "111 Main St." & vbCr & "Charlotte, NC 28226"
End With
' Save Contact...
itmContact.Save
Set ol = Nothing
Set ns = Nothing
Set itmContact = Nothing
MsgBox "Done."
That works, but what I would like to do is...upon clicking the button that executes that code, I would like it to find the Contact folder named '123'...clear the contacts from it....then add the contact above. When I try working with addresslists (like I did in 2k3), I get errors saying Type Mismatch.
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Aug 13th, 2007, 08:06 AM
#2
Re: Create Contact in Folder/Delete Contact in Folder
Well you are not loggin on to the outlook profile/session that may be one part. You are using Early Binding that is specific to 2003 reference. For this you should be using Late Binding with no reference to Outlook.
See my faq item on Early and Late binding
http://vbforums.com/showthread.php?t=406640
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 13th, 2007, 08:29 AM
#3
Thread Starter
Hyperactive Member
Re: Create Contact in Folder/Delete Contact in Folder
I just looked, and that post speaks of sending a mail message...but not saving a contact...im sorry if I sound really stupid with this. The above code works fine...do you perhaps know the syntax to add it to a specific contact folder (instead of the root contact folder)?
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Aug 13th, 2007, 09:50 AM
#4
Re: Create Contact in Folder/Delete Contact in Folder
Well I guess you didnt read it then as that was not about sending email but the process of Early binding vs Late binding and how it can help you to support multiple versions of Outlook. What is generating the type mismatch error?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 7th, 2007, 05:27 AM
#5
Lively Member
Re: Create Contact in Folder/Delete Contact in Folder
I have the same problem:
i know, how to find, add, delete, update a contact-item, BUT:
i want to do all the operations NOT in the default contact folder, but in
my own contact folder named "sigiK" - so i first have to find this folder out from outlook - how can i do this ??
-
Sep 7th, 2007, 06:42 AM
#6
Lively Member
Re: Create Contact in Folder/Delete Contact in Folder
solved ...
finding myFolder:
Code:
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim oContacts As Outlook.MAPIFolder
oContacts = FindMyFolder(oNS.Folders)
Private Function FindMyFolder(ByVal F As Outlook.Folders) As Outlook.MAPIFolder
Dim wf As Outlook.MAPIFolder
Dim cf As Outlook.MAPIFolder
For Each wf In F
If wf.Name = "MyFolder" Then Return wf
If wf.Folders.Count > 0 Then
cf = FindMyFolder(wf.Folders)
If Not cf Is Nothing Then Return cf
End If
Next
Return Nothing
End Function
adding contact:
Code:
oContact = oContacts.Items.Add
With oContact
.LastName = ....
[.......]
.User1 = 5
.Save()
End With
finding contact:
Code:
oContact = oContacts.Items.Find("[User1] = '5'")
sorry, if code seems stupid, but i am a greenhorn ...
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
|