473,804 Members | 3,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with "Outlook-Contacts"

Hello!

I think, I have one simple question for you guys, but I don't get the answer
by myself!

I would like to import all "Outlook - Contacts" into my application and when
I use "foreach" it works! But with "Outlook 2002" I must use a "for - Loop"
and that is my problem! I have three contacts in Outlook and when I import
the "contacts", it gives me everytime only two contacts!

Here is my "for - loop" and I hope one of you could find my (simple) mistake!

*********
int zaehler;

object item = (MSOutlook.Cont actItem)objFold er.Items.GetFir st();

for (zaehler = 0; zaehler <= objFolder.Items .Count; zaehler++)
{
appItem = item as MSOutlook.Conta ctItem;

if (appItem != null)
{
importContactIt ems.Tables[0].Rows.Add(new object[] {
appItem.LastNam e, appItem.FirstNa me, appItem.
HomeAddressStre et,
appItem.HomeAdd ressPostalCode, appItem.HomeAdd ressCity});
item = (MSOutlook.Cont actItem)objFold er.Items.GetNex t();
zaehler++;
}
}
**********

Regards

Corey

P.S. Sry, for my bad english! *g

Mar 13 '07 #1
4 1464
Hi Corey,

Corey66 schrieb:
for (zaehler = 0; zaehler <= objFolder.Items .Count; zaehler++)
{
zaehler++;
There's your problem: You increment zaehler within the for loop, but the
for loop itself increments already.
}
Hope this helps,

Cheers,

Roland
Mar 14 '07 #2
Thx for your help!

But when I have three Contacts, he shows me that the three Contacts exists,
but he I don't get the last one!
He shows me the first two Contacts in my table, but the third record is my
second Contact again! :-(

My new Code:

int zaehler;

object item = (MSOutlook.Cont actItem)objFold er.Items.GetFir st();

// Get the number of my "Contacts"
MessageBox.Show (objFolder.Item s.Count.ToStrin g());

MSOutlook.Conta ctItem appItem

for (zaehler = 0; zaehler <= objFolder.Items .Count-1; zaehler++)
{
appItem = item as MSOutlook.Conta ctItem;

if (appItem != null)
{
importContactIt ems.Tables[0].Rows.Add(new object[] {
appItem.LastNam e, appItem.FirstNa me, appItem.HomeAdd ressStreet,
appItem.HomeAdd ressPostalCode, appItem.HomeAdd ressCity});

item = (MSOutlook.Cont actItem)objFold er.Items.GetNex t();
}
}

--
Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...sharp/200703/1

Mar 14 '07 #3
Can nobody help me? :-(

Regards

Corey

--
Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...sharp/200703/1

Mar 15 '07 #4
On Mar 15, 3:51 am, "Corey66 via DotNetMonster.c om" <u32452@uwe>
wrote:
Can nobody help me? :-(

Regards

Corey

--
Message posted via DotNetMonster.c omhttp://www.dotnetmonst er.com/Uwe/Forums.aspx/dotnet-csharp/200703/1
Why don't you try using a foreach loop instead. It will be cleaner:

// Get the number of my "Contacts"
MessageBox.Show (objFolder.Item s.Count.ToStrin g());

foreach (MSOutlook.Cont actItem appItem in objFolder.Items )
{

if (appItem != null)
{
importContactIt ems.Tables[0].Rows.Add(new object[] {
appItem.LastNam e, appItem.FirstNa me, appItem.HomeAdd ressStreet,
appItem.HomeAdd ressPostalCode, appItem.HomeAdd ressCity});
}

}

Mar 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2636
by: Alexander | last post by:
To all, A tall order, but any help on any segment of this would be appreciated: I have a table that needs to be populated with information contained in an email attachment. 1. Is it possible for Outlook to "notify" Access that an email has been received?
1
2239
by: deko | last post by:
This sub pulls Outlook Appointments into a table. The problem is I want to limit the import to Location = Boston I'm not sure how to code that into the For... To loop - As it is now, I get the following error: Run-time error '3163': The field is too small to accept the amount of data you attempted to add. Try inserting less data.
0
326
by: sasha | last post by:
Hi All How we can access "Outlook Express". The senerio is: An ASPX file (in C#) should retrieve the contact info from "Outlook express" adress book. Any help appreciated. Thanks
0
6233
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I am trying to create a windows service that will add and remove items from outlooks itemlist. But when i create the outlook application instance i get the message "Rejected Safe Mode action : Microsoft Outlook" What is this?! Isn't this instance threadsafe? How should i connect to outlook from a windows service?
8
4857
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item I want to raise the ProgressChanged-event to update the DataGridView. It works fine when only one Progresschanged is fired, but at the second, third, fopurth etc it raises everytile a 'Cross-thread operation not valid"-exception on lmy...
2
10526
by: mik.sjoblom | last post by:
Hello, I have developed a Access application that needs to read mail from Outlook, versions on Access and outlook are 2003. In the code i use mapi to connect to outlook. When i tries to read the subject of a message outlook displays "A program is trying to access e-mail adresses you have stored in Outlook. Do you want to allow this." And then i can allow access for max 10 minutes. My application is use scheduled statupm creating reports...
14
4493
by: BillCo | last post by:
Hi folks, I have an a2k ap which is called from a batch file via task scheduler on at night - it runs a bunch of updates, imports stuff from other databases and generally preps the main backend for another day's work. It logs everything and generates an email which it sends to a few people, issuing warnings if there were problems. Have you guessed the problem yet? Outlook 2003 / SP2 - "...Trying to send a mail...", "...use address
2
9514
by: =?Utf-8?B?UmFscGggSQ==?= | last post by:
OK, Dell inspirion 9300 - 100 gb hd partitioned into 3 drives C: OS 10 gb D: Programs 20 gb E: Data 70 GB Page Files 0 on C: 4092 on D: 3070 on E:
1
1778
by: =?Utf-8?B?R29yZG9uUw==?= | last post by:
Hello, I am unsure which group this should go under so have placed it on the general, if anybody can suggest a more appropriate group that would be great. I have a problem whereby if I update an Outlook 2007 calendar item via an external program (eg. by Exchange Explorer or Exchange 2007 Web Services) I am unable to update that item in Outlook itself until I restart the application.
1
3593
by: =?Utf-8?B?c3DDr3LDtg==?= | last post by:
I'm having a problem with MS outlook. Neither of my email accounts were working, so I reinstalled hoping that, that would fix the problem - unfortunatly it didn't. When I go to create a new hotmail account, I fill in all the details and when I click "more settings" or "next" I get a message: "The requested operation failed"
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.