• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Create new contact on specific form

Hello all

I just add this new code on my project.

Then, i have created a new form for adding new contact, and then put it has default.

But when i use this code, it does not appy on my new default form. I takes the one that was in default before.

My new form name is "TEST FORM".

Where do i modify the code so that it use the new form?

Thanks again for your help.


   Private Sub CréerNouveauClientToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CréerNouveauClientToolStripMenuItem.Click
        Dim oApp As Outlook.Application
        oApp = CreateObject("Outlook.Application")

        Dim oNs As Outlook.NameSpace
        oNs = oApp.GetNamespace("MAPI")
        oNs.Logon()

        Dim oItem As Outlook.ContactItem
        oItem = oApp.CreateItem(OlItemType.olContactItem)

        With oItem
            .FullName = "AuthorCode"
            .CompanyName = "AuthorCODE"
            .Email1Address = "contactus@authorcode.com"
            .JobTitle = "Developer"
            .HomeAddress = "Delhi,India"
            .BusinessAddress = "Delhi,India"
            .Email1Address = "supoerttools@authorcode.com"
        End With
        oItem.Save()

        MsgBox("Sauvegarder")
    End Sub

Open in new window

0
Wilder1626
Asked:
Wilder1626
  • 11
  • 6
1 Solution
 
käµfm³d 👽Commented:
I'm not sure I understand the problem, but perhaps you haven't updated the Handles clause?

Private Sub CréerNouveauClientToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CréerNouveauClientToolStripMenuItem.Click
0
 
Wilder1626Author Commented:
Sorry, i will try to give more details.

When you want to manually enter a new contact in Microsoft Outlook 2007, there is a form for that.

Since i did not like that form for adding a new contact, i decided to create a custom one, with only the fields i need.

Ex:

Full name
Telephone
cell
Address
City
Province
Postal code
Email......

After that, i when into the Contact properties and i applied the new custom contact form by default.

Now, if i create a new contact directly in Outlook, i see my new form.

But the problem i have now, it is to fix my vb.net code so that when i create a new contact, directly in my project.net, that it will send the information in my new custom form.

Now, what it's doing, it is sending the information on the previous form.

Does it make sense?

Please let me know.

Thanks again.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
Wilder.

Instead of using .NET to control an Outlook form, why don't you create a Form in .NET and use the content of that form to add the new Contact to Outlook. Seems to me that it would make things easier, since you can do a lot more in a .NET form than in an Outlook form.

If you need to stick to the Outlook form for some reason, there are great chances that somebody who know about those would be better suited to give you a proper answer than somebody who is good in VB.NET. I would also post this in an Outlook, VBA.Outlook or VBA.Office forum. The answer you would get there should then be easyly applied to your .NET code.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Wilder1626Author Commented:
Hello JamesBurger

I have already created a Form in .NET.

But i need to be able to split the address files since by default, in the official master contact form from Outlook, they are all in the same textbox.

This is the form i have created: See picture.


Is there another way in vb.net to separate the address fields?

add-contact.net.jpg
0
 
Wilder1626Author Commented:
Sorry, i wanted to say: But i need to be able to split the address fields since by default, in the official master contact form from Outlook, they are all in the same textbox.
0
 
Wilder1626Author Commented:
And is the sauverder button, i would have a code like this:

  Dim oApp As Outlook.Application
        oApp = CreateObject("Outlook.Application")

        Dim oNs As Outlook.NameSpace
        oNs = oApp.GetNamespace("MAPI")
        oNs.Logon()

        Dim oItem As Outlook.ContactItem
        oItem = oApp.CreateItem(OlItemType.olContactItem)

        With oItem
            .FullName = Me.nom_prenom.Text
            .ville_domicile = Me.ville.Text
            .Email1Address = Me.courriel.Text
            .postal_code = Me.code_postal.Text
        End With
        oItem.Save()


        'Transfert contact to form 2
        Form2.client.Text = Me.nom_prenom.Text
        Form2.courriel.Text = Me.courriel.Text
        Form2.address.Text = Me.adresse_residentiel.Text
        Form2.ville.Text = Me.ville.Text
        Form2.telephone.Text = Me.telephone.Text
        Form2.code_postal.Text = Me.code_postal.Text
        Me.Close()



        MsgBox("Sauvegarder")

Open in new window

0
 
Jacques Bourgeois (James Burger)PresidentCommented:
There seems to be many different problems in different posts. And different forms too, a custom one in Outlook and one in .NET.

Let's try to make things clear.

-----

"it is sending the information on the previous form."

We do not see any form in your code. What form? Your .NET form or your custom Outlook form? How do you display, hide, close the form. The problem is probably there somewhere.

-----

"'i need to be able to split the address files since by default, in the official master contact form from Outlook, they are all in the same textbox"

When you type the address in Outlook, it comes out as one String, but ends up in different fields in the Contact information (BusinessAddress, BusinessAddressCity and so on).

You want to do the same thing in .NET, do I understand well?

If so, Bonne chance pour celle-là (good luck on that one).

The algorithm to do that would be very complex. Here are just a few clues.

You first need to separate the lines. This one is easy, with the Split method of the String class.

It's after that that it gets complex, because not 2 users will type the filed the same way (no matter if you insist on a given format). Here are just a few of the things to consider.

Sometimes theres is a coma between the street number, sometimes not.
Sometimes the city, province/state and postal/zip code are on one line, sometimes on 2, sometimes on 3.
State or province might be a word or the code, and some of them can have many forms (Québec, Quebec, QC, PQ).
In Canada, the province is sometimes in enclosed between parenthesis, sometimes not.
And i could go on for a while.

You might try to find an algorithm to do that, but it would never be OK. The one in Outlook often makes mistakes.

The way you are getting the address in the .NET form you sent us is a lot better, believe me.
0
 
Wilder1626Author Commented:
Ok, so i will continue to use the form i did, i just need to look how i will be able to transfer all the testbox in each fields in outlook.

I will forget about the custom form in Outlook.

I will also search how to name the oItem fields

These worke:
  With oItem
            .FullName = Me.nom_prenom.Text
            .Email1Address = Me.courriel.Text
        End With

But i need to find the rest.

I will do some googling see if i found something.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
You do not need to "search" for the other fields. Don't you get the list of fields when you type "oItem." and stop there? They are all there.
0
 
Wilder1626Author Commented:
But how will it know where to send the textbox text tothe right place in oItem?

Ex:
.FullName = Me.nom_prenom.Text
            .Email1Address = Me.courriel.Text

It send the Me.nom_prenom.Text in the FullName field.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
Either you split the name entry in 2 entries, txtPrénom and txtNom and go this way:

.FirstName = txtPrénom.Text
.LastName = txtNom.Text

Don't you see those 2 fields in the IntelliSense list?

Or you send what you have now to .FullName, as you do in your last piece of code, and let Outlook do the split as it does usually, that means OK if they are in 2 words, but a mess if they are in more than 2 words.
0
 
Wilder1626Author Commented:
For the name, i was sending  in full name. But that is ok.

Where i block is for these fields: address / City / Postal code / Province.


Where exactly do i find this IntelliSense list.

i have extract from outlook all fileds but if i use the heaaders, it does noy work:


ex:
'Ruedomicile
'Villedomicile
'DépRégiondomicile
'Codepostaldomicile

This is the portin where i think i don't understand to much.

If i google IntelliSense list, it does not say a lot.
0
 
Wilder1626Author Commented:
oh, i think i understand.

Let me try something
0
 
Wilder1626Author Commented:
Ohhhh! Got it now.

Thanks for your patience with me. Once i understand, it help. :-)

 With oItem
            'Full name
            .FullName = Me.nom_prenom.Text

            'Home Address
            .HomeAddressStreet = Me.adresse_residentiel.Text

            'Home City
            .HomeAddressCity = Me.ville.Text

            'Home Province
            .HomeAddressState = Me.province.Text

            'Home Postal code
            .HomeAddressPostalCode = Me.code_postal.Text

            'Home Téléphone
            .HomeTelephoneNumber = Me.telephone.Text

            'Home cell
            .Home2TelephoneNumber = Me.cellulaire.Text

            'Email address
            .Email1Address = Me.courriel.Text

Open in new window

0
 
Wilder1626Author Commented:
Thanks again for your patience with me. I really appreciate your help all the time.

When i do it once, i remember. :-P
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
My job is to teach the stuff.

So patience is my job.

Think what it is when I am in a classroom with 12 programmers that all have different needs and backgrounds.

Helping you is a charm, because you want to learn and do not give up.

Et je ne vois pas souvent des champs Prénom et Nom sur ce site (I do not see French labels often on this site). Saint-Basile (if I remember well) and Longueuil are not too far apart. I am always glad to help a neighbour.
0
 
Wilder1626Author Commented:
Since i work in Boucherville also, it's bout 10 minutes from St-Basile. So to Longueuil about 5 minutes more. So it is very not to far apart.

Thanks again to you.

I will probably go for now vb.net training. That will surly help me more.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
If .NET is part of your work, training will help a lot. I have people in my class that have been at it for a few years and find out that a lot of what they where doing was wrong or could have been a lot simpler.

Maybe I will have the chance to have you in my class one of these days (Cours VB.NET)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 11
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now