Solved

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

Posted on 2004-08-02
5
306 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

20 Experts available now in Live!

Get 1:1 Help Now