vb.net and this window application giving me this error, i have underlined where code breaks. Any idea why?


An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication20.exe

Additional information: The operation failed.

Dim rst
Dim dao
Dim wks
Dim db
Dim nms
Dim fld
Dim itms
Dim itm
Dim strAccessDir
Dim objAccess
Dim strFolder
Dim fFound

Dim oApp As Outlook.Application = New Outlook.Application
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim pf As Outlook.MAPIFolder = oNS.Folders("Public Folders").Folders("All Public Folders")
Dim cContacts As Outlook.MAPIFolder = pf.Folders("Contacts")
Dim itt As Outlook.ContactItem
Dim strdbname


objAccess = oApp.CreateObject("Access.Application")
strAccessDir = objAccess.SysCmd(9)
strdbname = strAccessDir & "Contacts.mdb"

objAccess.Quit()

dao = oApp.CreateObject("DAO.DBEngine.35")
wks = dao.Workspaces(0)
db = wks.OpenDatabase(strdbname)


rst = db.OpenRecordset("tblCustomers")
Dim RecCount = rst.RecordCount
If RecCount = 0 Then
MsgBox("No customers to import")
Exit Sub
Else
MsgBox(RecCount, " customers to import")
End If

oNS = oApp.GetNamespace("MAPI")
pf = oNS.Folders("Public Folders").Folders("All Public Folders")
itm = pf.itms


Do Until rst.EOF

itm = itms.Add("IPM.Contact.Access Contact")


If IsDBNull(rst.CustomerID) = False Then itm.CustomerID = rst.CustomerID
If IsDBNull(rst.CompanyName) = False Then itm.CompanyName = rst.CompanyName
If IsDBNull(rst.ContactName) = False Then itm.FullName = rst.ContactName
If IsDBNull(rst.Address) = False Then itm.BusinessAddressStreet = rst.Address
If IsDBNull(rst.City) = False Then itm.BusinessAddressCity = rst.City
If IsDBNull(rst.Region) = False Then itm.BusinessAddressState = rst.Region
If IsDBNull(rst.PostalCode) = False Then itm.BusinessAddressPostalCode = rst.PostalCode
If IsDBNull(rst.Country) = False Then itm.BusinessAddressCountry = rst.Country
If IsDBNull(rst.Phone) = False Then itm.BusinessTelephoneNumber = rst.Phone
If IsDBNull(rst.Fax) = False Then itm.BusinessFaxNumber = rst.Fax
If IsDBNull(rst.ContactTitle) = False Then itm.JobTitle = rst.ContactTitle

itm.Close(0)
rst.MoveNext()

Loop
rst.Close()
MsgBox("All contacts imported!")