Results 1 to 5 of 5
  1. #1
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22

    Creating Outlook Contact - Error Msg

    I'm using the following function and calling it with a command button:



    Code:
    Function AddOlContact()
    On Error GoTo Error_Handler
      Const olContactItem = 2
      Dim olApp As Object
      Dim Ctct As Object
     
      Set olApp = CreateObject("Outlook.Application")
      Set olContact = olApp.CreateItem(olContactItem)
     
      With olContact
        .FirstName = Me.FirstName.Value
        .LastName = Me.LastName.Value
        .JobTitle = Me.Title.Value
        .CompanyName = Me.OriginatorName.Value
        .BusinessAddressStreet = ""
        .BusinessAddressCity = ""
        .BusinessAddressState = ""
        .BusinessAddressCountry = ""
        .BusinessAddressPostalCode = ""
        .BusinessTelephoneNumber = Me.BusinessPhone.Value
        .BusinessFaxNumber = Me.Fax.Value
        .Email1Address = "Me.Email.Value"
        .MobileTelephoneNumber = Me.CellPhone.Value
        .Display 'use .Display if you wish the user to see the contact pop-up
      End With
     
    Error_Handler_Exit:
      On Error Resume Next
      Set olContact = Nothing
      Set olApp = Nothing
      Exit Function
     
    Error_Handler:
      MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
      Err.Number & vbCrLf & "Error Source: AddOlContact" & vbCrLf & "Error Description: " & _
      Err.Description, vbCritical, "An Error has Occured!"
      Resume Error_Handler_Exit
         End Function
    However if a field is blank I get an error msg saying access doesn't support it. Any thoughts how to get around the error in the even a field is blank?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    So you are able to assign an empty string but you are not able to assign the value of a control if the control is Null?

    Maybe
    Code:
    Dim strBusPhone as string
    strBusPhone = ""
    if not isnull(Me.BusinessPhone.Value) Then
    strBusPhone = Me.BusinessPhone.Value
    end if
    And then in your Outlook Code
    Code:
    .BusinessTelephoneNumber = strBusPhone

  3. #3
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22
    Quote Originally Posted by ItsMe View Post
    So you are able to assign an empty string but you are not able to assign the value of a control if the control is Null?

    Maybe
    Code:
    Dim strBusPhone as string
    strBusPhone = ""
    if not isnull(Me.BusinessPhone.Value) Then
    strBusPhone = Me.BusinessPhone.Value
    end if
    And then in your Outlook Code
    Code:
    .BusinessTelephoneNumber = strBusPhone
    I was playing around with "If" options but couldn't it to work, I think your approach may do the trick. Will report back. Thanks!

  4. #4
    sashapixie is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    1
    Try Nz(Me.FirstName, "")

  5. #5
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22
    Quote Originally Posted by sashapixie View Post
    Try Nz(Me.FirstName, "")
    Will give that a shot, ItsMe's solution worked, but it is a lot of code. If the Nz option works it may be cleaner. Thanks Sasha!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Add Contact from Outlook in a Subform
    By rapaint66 in forum Access
    Replies: 3
    Last Post: 08-29-2014, 09:37 AM
  2. Export contact information from Outlook to Access
    By erikl1 in forum Import/Export Data
    Replies: 14
    Last Post: 12-31-2013, 06:36 AM
  3. Link existing names in Access DB to Outlook contact
    By mikejoka in forum Import/Export Data
    Replies: 1
    Last Post: 08-30-2013, 12:24 PM
  4. add to Outlook Contact
    By sdel_nevo in forum Programming
    Replies: 2
    Last Post: 06-10-2013, 01:07 AM
  5. Replies: 0
    Last Post: 06-19-2007, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums