Populate Outlook Contact form with Access data

C

CCripe

I want to create a button that opens an Outlook contact form and populates it
with data from the Access database. When I click the button on the form, it
looks like it's going to work and then I get this error: "Object doesn't
support this property or method." Below is my code. Any help is GREATLY
appreciated.

Private Sub Command105_Click()
On Error GoTo Err_Command105_Click

Dim ol As Outlook.Application
Set ol = CreateObject("Outlook.Application")
Dim ns As NameSpace
Set ns = ol.GetNamespace("Mapi")
Dim NewContact As ContactItem

ns.Logon , , True
Set NewContact = ol.CreateItem(olContactItem)

With NewContact
.First Name = Forms!frmProspect!sfrmContacts!FirstName
.Last Name = Forms!frmProspect!sfrmContacts!LastName
.BusinessPhone = Forms!frmProspect!sfrmContacts!DirectNumber
.MobilePhone = Forms!frmProspect!sfrmContacts!CellPhone
.EmailAddress = Forms!frmProspect!sfrmContacts!EmailAddress

End With

Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_Command105_Click:
Exit Sub

Err_Command105_Click:
MsgBox Err.Description
Resume Exit_Command105_Click


End Sub
 
D

Daniel Pineault

The following is something I had put together a while back to help out a
friend. It created outlook contact entries based on Excel cell values. You
should easily be able to adapt it to use your Form data instead of the cell
values.


Dim olApp As Outlook.Application
Dim nspNameSpace As Outlook.Namespace
Dim objContacts As Object
Dim objContact As Outlook.ContactItem


' Get reference to the Outlook Contacts folder.
Set olApp = New Outlook.Application
Set nspNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = nspNameSpace.GetDefaultFolder(olFolderContacts).Items

Dim LastRow As Long
LastRow = [C65536].End(xlUp).Row 'determine the last cell used

For i = 2 To LastRow 'LastRow

'append contact
Set objContact = objContacts.Add

'fill contact
With objContact
'.CustomerID = Me.ContactID
.LastName = Sheets("Sheet1").Range("A" & i).Value
.FirstName = Sheets("Sheet1").Range("B" & i).Value
'.HomeAddress = Sheets("Sheet1").Range("B" & i).Value
'.HomeAddressCity = Sheets("Sheet1").Range("B" & i).Value
'.BusinessAddress = Sheets("Sheet1").Range("B" & i).Value
'.BusinessAddressCity = Sheets("Sheet1").Range("B" & i).Value
'.HomeTelephoneNumber = Sheets("Sheet1").Range("B" & i).Value
'.BusinessTelephoneNumber = Sheets("Sheet1").Range("B" & i).Value
'.Body = Sheets("Sheet1").Range("B" & i).Value '.Body is that
big field on the contact form
.Email1Address = Sheets("Sheet1").Range("C" & i).Value
.Body = Sheets("Sheet1").Range("D" & i).Value
.Save
End With
Next i


Set olApp = Nothing
Set nspNameSpace = Nothing
Set objContacts = Nothing
Set objContact = Nothing


--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.com/index.php
Please rate this post using the vote buttons if it was helpful.
 
C

CCripe

Had a problem:

It throws up this error: "Object Variable or With block variable not set"

Daniel Pineault said:
The following is something I had put together a while back to help out a
friend. It created outlook contact entries based on Excel cell values. You
should easily be able to adapt it to use your Form data instead of the cell
values.


Dim olApp As Outlook.Application
Dim nspNameSpace As Outlook.Namespace
Dim objContacts As Object
Dim objContact As Outlook.ContactItem


' Get reference to the Outlook Contacts folder.
Set olApp = New Outlook.Application
Set nspNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = nspNameSpace.GetDefaultFolder(olFolderContacts).Items

Dim LastRow As Long
LastRow = [C65536].End(xlUp).Row 'determine the last cell used

For i = 2 To LastRow 'LastRow

'append contact
Set objContact = objContacts.Add

'fill contact
With objContact
'.CustomerID = Me.ContactID
.LastName = Sheets("Sheet1").Range("A" & i).Value
.FirstName = Sheets("Sheet1").Range("B" & i).Value
'.HomeAddress = Sheets("Sheet1").Range("B" & i).Value
'.HomeAddressCity = Sheets("Sheet1").Range("B" & i).Value
'.BusinessAddress = Sheets("Sheet1").Range("B" & i).Value
'.BusinessAddressCity = Sheets("Sheet1").Range("B" & i).Value
'.HomeTelephoneNumber = Sheets("Sheet1").Range("B" & i).Value
'.BusinessTelephoneNumber = Sheets("Sheet1").Range("B" & i).Value
'.Body = Sheets("Sheet1").Range("B" & i).Value '.Body is that
big field on the contact form
.Email1Address = Sheets("Sheet1").Range("C" & i).Value
.Body = Sheets("Sheet1").Range("D" & i).Value
.Save
End With
Next i


Set olApp = Nothing
Set nspNameSpace = Nothing
Set objContacts = Nothing
Set objContact = Nothing


--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.com/index.php
Please rate this post using the vote buttons if it was helpful.



CCripe said:
I want to create a button that opens an Outlook contact form and populates it
with data from the Access database. When I click the button on the form, it
looks like it's going to work and then I get this error: "Object doesn't
support this property or method." Below is my code. Any help is GREATLY
appreciated.

Private Sub Command105_Click()
On Error GoTo Err_Command105_Click

Dim ol As Outlook.Application
Set ol = CreateObject("Outlook.Application")
Dim ns As NameSpace
Set ns = ol.GetNamespace("Mapi")
Dim NewContact As ContactItem

ns.Logon , , True
Set NewContact = ol.CreateItem(olContactItem)

With NewContact
.First Name = Forms!frmProspect!sfrmContacts!FirstName
.Last Name = Forms!frmProspect!sfrmContacts!LastName
.BusinessPhone = Forms!frmProspect!sfrmContacts!DirectNumber
.MobilePhone = Forms!frmProspect!sfrmContacts!CellPhone
.EmailAddress = Forms!frmProspect!sfrmContacts!EmailAddress

End With

Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_Command105_Click:
Exit Sub

Err_Command105_Click:
MsgBox Err.Description
Resume Exit_Command105_Click


End Sub
 
D

Daniel Pineault

The following has been tested in Access 2003

Function CreateNewContact(Optional strFolder As String)
'Creates a new contact entry in the specified folder
'Requires reference to Outlook be set

'strFolder is the folder in which to create the new contact

Dim olApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items

Set olApp = CreateObject("Outlook.Application")
Set myNameSpace = olApp.GetNamespace("MAPI")

If strFolder = "Contacts" Or IsMissing(strFolder) Or strFolder = "" Then
Set objFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Else
Set objFolder =
myNameSpace.GetDefaultFolder(olFolderContacts).Folders(strFolder)
End If

Set objItems = objFolder.Items
Set ObjAdd = objItems.Add

With ObjAdd 'Create new Contact Entry
.FirstName = "Daniel"
.LastName = "Pineault"
.HomeAddressStreet = "My Address"
.Save
End With


Set objItems = Nothing
Set objFolder = Nothing
Set myNameSpace = Nothing
Set olApp = Nothing

End Function
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.com/index.php
Please rate this post using the vote buttons if it was helpful.



CCripe said:
Had a problem:

It throws up this error: "Object Variable or With block variable not set"

Daniel Pineault said:
The following is something I had put together a while back to help out a
friend. It created outlook contact entries based on Excel cell values. You
should easily be able to adapt it to use your Form data instead of the cell
values.


Dim olApp As Outlook.Application
Dim nspNameSpace As Outlook.Namespace
Dim objContacts As Object
Dim objContact As Outlook.ContactItem


' Get reference to the Outlook Contacts folder.
Set olApp = New Outlook.Application
Set nspNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = nspNameSpace.GetDefaultFolder(olFolderContacts).Items

Dim LastRow As Long
LastRow = [C65536].End(xlUp).Row 'determine the last cell used

For i = 2 To LastRow 'LastRow

'append contact
Set objContact = objContacts.Add

'fill contact
With objContact
'.CustomerID = Me.ContactID
.LastName = Sheets("Sheet1").Range("A" & i).Value
.FirstName = Sheets("Sheet1").Range("B" & i).Value
'.HomeAddress = Sheets("Sheet1").Range("B" & i).Value
'.HomeAddressCity = Sheets("Sheet1").Range("B" & i).Value
'.BusinessAddress = Sheets("Sheet1").Range("B" & i).Value
'.BusinessAddressCity = Sheets("Sheet1").Range("B" & i).Value
'.HomeTelephoneNumber = Sheets("Sheet1").Range("B" & i).Value
'.BusinessTelephoneNumber = Sheets("Sheet1").Range("B" & i).Value
'.Body = Sheets("Sheet1").Range("B" & i).Value '.Body is that
big field on the contact form
.Email1Address = Sheets("Sheet1").Range("C" & i).Value
.Body = Sheets("Sheet1").Range("D" & i).Value
.Save
End With
Next i


Set olApp = Nothing
Set nspNameSpace = Nothing
Set objContacts = Nothing
Set objContact = Nothing


--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.com/index.php
Please rate this post using the vote buttons if it was helpful.



CCripe said:
I want to create a button that opens an Outlook contact form and populates it
with data from the Access database. When I click the button on the form, it
looks like it's going to work and then I get this error: "Object doesn't
support this property or method." Below is my code. Any help is GREATLY
appreciated.

Private Sub Command105_Click()
On Error GoTo Err_Command105_Click

Dim ol As Outlook.Application
Set ol = CreateObject("Outlook.Application")
Dim ns As NameSpace
Set ns = ol.GetNamespace("Mapi")
Dim NewContact As ContactItem

ns.Logon , , True
Set NewContact = ol.CreateItem(olContactItem)

With NewContact
.First Name = Forms!frmProspect!sfrmContacts!FirstName
.Last Name = Forms!frmProspect!sfrmContacts!LastName
.BusinessPhone = Forms!frmProspect!sfrmContacts!DirectNumber
.MobilePhone = Forms!frmProspect!sfrmContacts!CellPhone
.EmailAddress = Forms!frmProspect!sfrmContacts!EmailAddress

End With

Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_Command105_Click:
Exit Sub

Err_Command105_Click:
MsgBox Err.Description
Resume Exit_Command105_Click


End Sub
 
D

DawnTreader

I want to create a button that opens an Outlook contact form and populatesit
with data from the Access database.  When I click the button on the form, it
looks like it's going to work and then I get this error: "Object doesn't
support this property or method."  Below is my code.  Any help is GREATLY
appreciated.

Private Sub Command105_Click()
On Error GoTo Err_Command105_Click

    Dim ol As Outlook.Application
    Set ol = CreateObject("Outlook.Application")
    Dim ns As NameSpace
    Set ns = ol.GetNamespace("Mapi")
    Dim NewContact As ContactItem

    ns.Logon , , True
    Set NewContact = ol.CreateItem(olContactItem)

    With NewContact
    .First Name = Forms!frmProspect!sfrmContacts!FirstName
    .Last Name = Forms!frmProspect!sfrmContacts!LastName
    .BusinessPhone = Forms!frmProspect!sfrmContacts!DirectNumber
    .MobilePhone = Forms!frmProspect!sfrmContacts!CellPhone
    .EmailAddress = Forms!frmProspect!sfrmContacts!EmailAddress

    End With

    Screen.PreviousControl.SetFocus
    DoCmd.FindNext

Exit_Command105_Click:
    Exit Sub

Err_Command105_Click:
    MsgBox Err.Description
    Resume Exit_Command105_Click

End Sub

it looks to me that maybe, and i am just guessing, as well i have not
tested the thought, but it looks like you are trying to cram the
fields into the outlook contact form. try putting an .value at the end
of the field lines.

eg. " Forms!frmProspect!sfrmContacts!FirstName.value"

hope it helps, because if it does then i might use it in my apps. :)
 
D

DawnTreader

The following has been tested in Access 2003

Function CreateNewContact(Optional strFolder As String)
'Creates a new contact entry in the specified folder
'Requires reference to Outlook be set

'strFolder is the folder in which to create the new contact

    Dim olApp           As Outlook.Application
    Dim myNameSpace     As Outlook.NameSpace
    Dim objFolder       As Outlook.MAPIFolder
    Dim objItems        As Outlook.Items

    Set olApp = CreateObject("Outlook.Application")
    Set myNameSpace = olApp.GetNamespace("MAPI")

    If strFolder = "Contacts" Or IsMissing(strFolder) Or strFolder = "" Then
        Set objFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
    Else
        Set objFolder =
myNameSpace.GetDefaultFolder(olFolderContacts).Folders(strFolder)
    End If

    Set objItems = objFolder.Items
    Set ObjAdd = objItems.Add

    With ObjAdd 'Create new Contact Entry
        .FirstName = "Daniel"
        .LastName = "Pineault"
        .HomeAddressStreet = "My Address"
        .Save
    End With

    Set objItems = Nothing
    Set objFolder = Nothing
    Set myNameSpace = Nothing
    Set olApp = Nothing

End Function
--
Hope this helps,

Daniel Pineaulthttp://www.cardaconsultants.com/
For Access Tips and Examples:http://www.devhut.com/index.php
Please rate this post using the vote buttons if it was helpful.



CCripe said:
Had a problem:
It throws up this error: "Object Variable or With block variable not set"
The following is something I had put together a while back to help outa
friend.  It created outlook contact entries based on Excel cell values.  You
should easily be able to adapt it to use your Form data instead of thecell
values.
    Dim olApp As Outlook.Application
    Dim nspNameSpace As Outlook.Namespace
    Dim objContacts As Object
    Dim objContact As Outlook.ContactItem
    ' Get reference to the Outlook Contacts folder.
    Set olApp = New Outlook.Application
    Set nspNameSpace = olApp.GetNamespace("MAPI")
    Set objContacts = nspNameSpace.GetDefaultFolder(olFolderContacts).Items
    Dim LastRow     As Long
    LastRow = [C65536].End(xlUp).Row 'determine the last cell used
    For i = 2 To LastRow 'LastRow
        'append contact
        Set objContact = objContacts.Add
        'fill contact
        With objContact
            '.CustomerID = Me.ContactID
            .LastName = Sheets("Sheet1").Range("A" & i).Value
            .FirstName = Sheets("Sheet1").Range("B" & i)..Value
            '.HomeAddress = Sheets("Sheet1").Range("B" &i).Value
            '.HomeAddressCity = Sheets("Sheet1").Range("B" & i).Value
            '.BusinessAddress = Sheets("Sheet1").Range("B" & i).Value
            '.BusinessAddressCity = Sheets("Sheet1").Range("B" & i).Value
            '.HomeTelephoneNumber = Sheets("Sheet1").Range("B" & i).Value
            '.BusinessTelephoneNumber = Sheets("Sheet1")..Range("B" & i).Value
            '.Body = Sheets("Sheet1").Range("B" & i).Value   '.Body is that
big field on the contact form
            .Email1Address = Sheets("Sheet1").Range("C" & i).Value
            .Body = Sheets("Sheet1").Range("D" & i).Value
            .Save
        End With
    Next i
Set olApp = Nothing
Set nspNameSpace = Nothing
Set objContacts = Nothing
Set objContact = Nothing
--
Hope this helps,
Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples:http://www.devhut.com/index.php
Please rate this post using the vote buttons if it was helpful.
:
I want to create a button that opens an Outlook contact form and populates it
with data from the Access database.  When I click the button on the form, it
looks like it's going to work and then I get this error: "Object doesn't
support this property or method."  Below is my code.  Any help is GREATLY
appreciated.
Private Sub Command105_Click()
On Error GoTo Err_Command105_Click
    Dim ol As Outlook.Application
    Set ol = CreateObject("Outlook.Application")
    Dim ns As NameSpace
    Set ns = ol.GetNamespace("Mapi")
    Dim NewContact As ContactItem
    ns.Logon , , True
    Set NewContact = ol.CreateItem(olContactItem)
    With NewContact
    .First Name = Forms!frmProspect!sfrmContacts!FirstName
    .Last Name = Forms!frmProspect!sfrmContacts!LastName
    .BusinessPhone = Forms!frmProspect!sfrmContacts!DirectNumber
    .MobilePhone = Forms!frmProspect!sfrmContacts!CellPhone
    .EmailAddress = Forms!frmProspect!sfrmContacts!EmailAddress
    End With
    Screen.PreviousControl.SetFocus
    DoCmd.FindNext
Exit_Command105_Click:
    Exit Sub
Err_Command105_Click:
    MsgBox Err.Description
    Resume Exit_Command105_Click
End Sub- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top