Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-22 : 19:05:52
|
I am trying to write a code in vb.net windows application that open my ms access table and get the rows and put in outlook public folders, but with this code below I am getting error, is it any other way that anybody can point out how to create object and open access? this is the error message An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication21.exe .I have jet 3.5 installed my c drive also. I have highlighted and underlined where error happens. 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() 'Set up reference to Access database dao = oApp.CreateObject("DAO.DBEngine.35") wks = dao.Workspaces(0) db = wks.OpenDatabase(strdbname) 'Open Access table containing data to import into Outlook 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 'Set up the Outlook folder and items and iterate 'through the Access table, adding one contact item using 'the custom form for each Access record 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") 'Built-in Outlook properties 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 'Custom Outlook properties itm.UserProperties("Preferred") = rst.Preferred itm.UserProperties("Discount") = rst.Discount itm.Close(0) rst.MoveNext() Loop rst.Close() MsgBox("All contacts imported!") End Sub |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-08-23 : 12:30:15
|
>> I am trying to write a code in vb.net windows applicationThat code is VB.NET or Vbscript? If you are coding in VB.NET, you should really turn on Option Explicit (and Option Strict), and in addition use references to the libaries you are using in your code, and not CreateObject.Then, if you encounter errors, they will be at compile time and it will be much easier to write and debug your code. If you are not familiar with this stuff, you might want to step back and get a good book on beginning VB.NET. Otherwise, you can just write the code in VBScript. |
 |
|
|
|
|
|
|