|
-
May 28th, 2002, 03:33 PM
#1
Thread Starter
Lively Member
Saving data into Microsoft Outlook
Hello,
I have 20,000 Names and phone numbers stored in the access table. Is there a way to use VB code to go to Microsoft Outlook under Contacts and create a Subfolder, and then go to the access table pulling the data (Names and phone numbers) and then save it into that Subfolder?
Thanks.
-
May 28th, 2002, 05:59 PM
#2
Fanatic Member
Here is how to create a sub-contact folder under the default contact folder and how to create a new ContactItem within that folder. All you have to do is add your database code and loop through the records and add a new item for each one. Let me know if you need anything else.
Code:
Public Sub CreateSubContactFolder()
Dim app As Outlook.Application, MFld As MAPIFolder, nItm As ContactItem
Set app = CreateObject("Outlook.Application")
Set MFld = app.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Folders.Add("Imported Contacts", olFolderContacts)
Set nItm = MFld.Items.Add(olContactItem)
nItm.FullName = "John A. Doe"
nItm.FileAs = "Doe, John A."
nItm.BusinessFaxNumber = "555-555-5555"
nItm.Email1Address = "[email protected]"
nItm.Save
nItm.Close olSave
Set nItm = Nothing
Set MFld = Nothing
Set app = Nothing
End Sub
BTW - I'm using Outlook 2000, but I believe this works the same in Outlook 97.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
May 28th, 2002, 09:42 PM
#3
Thread Starter
Lively Member
thank you very much RealisticGraphics, I'll give a try.
H.
-
May 29th, 2002, 11:01 AM
#4
Thread Starter
Lively Member
Hi RealisticGraphics,
The code that you provided works very good, but there's little tiny problem with that. Every time it goes throught line "nItm.BusinessFaxNumber", a small window(Location Information) pops up. Is there a way to avoid having that window to pop up?
Thanks
-
May 29th, 2002, 05:40 PM
#5
Thread Starter
Lively Member
And also when it saves a new contact info, it saves on top of the previous contact info. It doesn’t move next.
-
May 29th, 2002, 05:46 PM
#6
Fanatic Member
That sounds like you're not resetting the object each time through the loop. Besure that the "MFld.Items.Add(olContactItem)" statement is inside the loop and that the "Set nItm = Nothing" statement is just right after you close the contact.
Also, are you running on an exchange server? I can not duplicate the problem with the box coming up on Business Fax. I'm just running a pop account off it here but I know that I've seen the box before at work (if it is the same thing). Could you maybe post a screen capture of the box that is coming up? Thanks.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
May 29th, 2002, 06:09 PM
#7
Thread Starter
Lively Member
I've attached the screenshot see if you can figure it out.
Thanks
-
May 29th, 2002, 06:12 PM
#8
Fanatic Member
I don't see an attachment, try it again.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
May 29th, 2002, 07:23 PM
#9
Thread Starter
Lively Member
How do I attach a file. I used the Attach file but it doesn't seem to work. Any idea?
-
Jun 4th, 2002, 04:39 AM
#10
New Member
add to existing contacts folder
Hi there, this works like a dream when creating a new Contacts Folder, but what if I want to add contacts to an existing Contacts Folder?? I have played around with the set Mfld part, but am not sure what option to use there..
-
Jun 4th, 2002, 06:01 PM
#11
Fanatic Member
Just set a mapi folder object to the name of the folder you want to grab... For instance, lets say you want to add contacts to the Imported Contacts folder we just created. You'd just use the following code.
Code:
Dim app As Outlook.Application, MFld As MAPIFolder, EFld As MAPIFolder, nItm As ContactItem
Set app = CreateObject("Outlook.Application")
Set MFld = app.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
Set EFld = MFld.Folders.Item("Imported Contacts")
Set nItm = EFld.Items.Add(olContactItem)
nItm.FullName = "John A. Doe2"
nItm.FileAs = "Doe2, John A."
nItm.BusinessFaxNumber = "666-666-6666"
nItm.Email1Address = "[email protected]"
nItm.Save
nItm.Close olSave
Set nItm = Nothing
Set EFld = Nothing
Set MFld = Nothing
Set app = Nothing
Notice that you still have to set an object to the root folder. Let me know if you need anything else.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Jun 5th, 2002, 01:51 AM
#12
New Member
I understand, so if I only want to import contacts in my root contacts folder, I can omit this part "Set EFld = MFld.Folders.Item("Imported Contacts")" and refer only yo Mfld, right?
-
Jun 5th, 2002, 05:38 PM
#13
Fanatic Member
You've got it.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
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
|