[AccessD] Access to Outlook

Susan Harkins ssharkins at gmail.com
Mon Nov 12 16:16:23 CST 2007


I posted the following code on the tech list this weekend, but so far haven't resolved the problem I'm having. I'm trying to send Access values to Outlook as a new contact. The   Set itm = itms.Add("IPM.Contact") statement returns a can't set object variable error. 

Susan H. 




Function SendContactsToOutlook()

  Dim rst As New ADODB.Recordset
  Dim cnn As New ADODB.Connection
  '---------
  'Must set reference to Outlook library
  '---------
  Dim itms As Outlook.Items
  Dim itm As Outlook.ContactItem
  Set cnn = CurrentProject.Connection
  rst.Open "tblContacts", cnn

  'Outlook Folder name is hardcoded
  
  Set itm = itms.Add("IPM.Contact")
  
  With itm
    .CustomerID = Nz(rst!CustomerID)
    .FirstName = Nz(rst!FirstName)
    .LastName = Nz(rst!LastName)
    .Department = Nz(rst!Department)
    .Birthday = Nz(rst!Department)
    .Close (olSave)
    'DoCmd.RunCommand acCmdSaveRecord
  End With
  

   
  
  Set rst = Nothing
  Set cnn = Nothing
  Set itms = Nothing
  Set itm = Nothing
  
End Function


More information about the AccessD mailing list