?
Solved

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

Posted on 2004-08-02
5
Medium Priority
?
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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