Solved

Simple question, feel free to make fun. What's wrong with my VB.NET code here?

Posted on 2004-08-02
5
307 Views
Last Modified: 2010-05-18
Mkay, this is my application IN IT'S ENTIRETY right now. I just started to program again, so I'm tinkering with small chunks of the larger project I'm working towards.

I've built a small app that takes the string out of two textboxes, and assigns them to the FirstName and LastName fields in Outlook's contacts list.

It works the first time around, but when I try to type in a different name and then click the Add! button again, I get an error. I assume it's not making a new object the 2nd time around or somthing so it messes up. Any help would be appreciated.
0
Comment
Question by:Sootah
5 Comments
 
LVL 2

Author Comment

by:Sootah
ID: 11691371
Public Class Form1
    Dim oApp As Outlook.Application = New Outlook.Application()
    Dim oCt As Outlook.ContactItem = oApp.CreateItem(Outlook.OlItemType.olContactItem)
    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        oCt = oApp.CreateItem(Outlook.OlItemType.olContactItem)
        oCt.FirstName = TxtFirstName.Text
        oCt.LastName = TxtLastName.Text
        oCt.Save()

        oApp = Nothing
        oCt = Nothing
    End Sub
End Class
0
 
LVL 2

Author Comment

by:Sootah
ID: 11691374
The 2nd oCt declaration was something I was tinkering with. It wasn't there before.
0
 

Expert Comment

by:Edeldragon
ID: 11691407
Sootah

I think the problem is that you are setting oApp = Nothing during the button click procedure. If you take out the oApp=Nothing line, then your subroutine should work repeatedly.

HTH

ED
0
 
LVL 8

Accepted Solution

by:
rfgkev earned 250 total points
ID: 11691871
put the 2 lines
    Dim oApp As Outlook.Application = New Outlook.Application()
    Dim oCt As Outlook.ContactItem = oApp.CreateItem(Outlook.OlItemType.olContactItem)

inside your button_click method
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 11691908
Hi Sootach,
ED is correct you should either remove that line or instantaite the objects within the event handler like
Public Class Form1
        Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        Dim oApp As Outlook.Application = New Outlook.Application()
        Dim oCt As Outlook.ContactItem = oApp.CreateItem(Outlook.OlItemType.olContactItem)

        oCt = oApp.CreateItem(Outlook.OlItemType.olContactItem)
        oCt.FirstName = TxtFirstName.Text
        oCt.LastName = TxtLastName.Text
        oCt.Save()

        oApp = Nothing
        oCt = Nothing
    End Sub
End Class

or


Public Class Form1
       Dim oApp As Outlook.Application = New Outlook.Application()
        Dim oCt As Outlook.ContactItem = oApp.CreateItem(Outlook.OlItemType.olContactItem)

        Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
       
        oCt = oApp.CreateItem(Outlook.OlItemType.olContactItem)
        oCt.FirstName = TxtFirstName.Text
        oCt.LastName = TxtLastName.Text
        oCt.Save()

    End Sub
    when exiting the form call the following
            oApp = Nothing
        oCt = Nothing

   
End Class


Hope that this helps you

Regards,
Venki
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now