chrisgreen
Programmer
I have produced the following code that puts data from an Access table into outlook contacts.<br><br>At the moment it puts the data into the outlook default mail folder. I have access the all exchange mailboxes and I want to be able to send the data to contacts in a selected mailbox.<br><br>The piece of code imediately below I think is the bit I need to change and the bit in " " is the line that I think is correct.<br><br>Can anyone help me?<br><br>Set objOutlook = CreateObject("Outlook.Application"
<br> Set nms = objOutlook.GetNamespace("MAPI"
<br> Set fldContacts = nms.GetDefaultFolder (olFolderContacts) '*********<br> " 'Set fldContacts = nms.CreateRecipient(Chrisgreen)"<br><br><br><br><br>Private Sub cmdPushData_Click()<br><br>On Error GoTo Err_cmdPushData_Click<br><br> Dim dbs As Database<br> Dim rst As Recordset<br> Dim objOutlook As Outlook.Application<br> Dim nms As Outlook.NameSpace<br> Dim flds As Outlook.Folders<br> Dim fldContacts As Object<br> Dim itms As Object<br> Dim itm As Object<br> Dim strTitle As String<br> Dim strFirstName As String<br> Dim strMiddleName As String<br> Dim strLastName As String<br> Dim strSuffix As String<br> Dim strJobTitle As String<br> Dim strLastNameFirst As String<br> Dim strBusinessStreet As String<br> Dim strBusinessStreet2 As String<br> Dim strBusinessCity As String<br> Dim strBusinessState As String<br> Dim strBusinessPostalCode As String<br> Dim strBusinessCountry As String<br> Dim strBusinessPhone As String<br> Dim strBusinessFax As String<br> Dim strHomeStreet As String<br> Dim strHomeStreet2 As String<br> Dim strHomeCity As String<br> Dim strHomeState As String<br> Dim strHomePostalCode As String<br> Dim strHomeCountry As String<br> Dim strHomePhone As String<br> Dim strHomeFax As String<br> Dim strOtherStreet As String<br> Dim strOtherStreet2 As String<br> Dim strOtherCity As String<br> Dim strOtherState As String<br> Dim strOtherPostalCode As String<br> Dim strOtherCountry As String<br> Dim strOtherPhone As String<br> Dim strOtherFax As String<br> Dim strEMailAddress As String<br> Dim strEMailAddress2 As String<br> Dim strContactID As String<br> Dim strCRLF As String<br> Dim lngCount As Long<br> <br> strCRLF = Chr$(13) & Chr$(10)<br> <br> Set objOutlook = CreateObject("Outlook.Application"
<br> Set nms = objOutlook.GetNamespace("MAPI"
<br> 'Set fldContacts = nms.GetDefaultFolder(olFolderContacts) '*********<br> Set fldContacts = nms.CreateRecipient(Chrisgreen)<br> <br> Set itms = fldContacts.Items<br> <br> 'Get reference to data table<br> Set dbs = CurrentDb<br> Set rst = dbs![tblContacts].OpenRecordset(dbOpenTable, dbDenyRead)<br> lngCount = rst.RecordCount<br> MsgBox lngCount & " records to transfer to Outlook"<br><br> 'Loop through table, exporting each record to Outlook<br> Do Until rst.EOF<br> With rst<br> 'Pick up data from a record<br> strContactID = Nz(![CustomerID])<br> strTitle = Nz(![Title])<br> strFirstName = Nz(![FirstName])<br> strMiddleName = Nz(![MiddleName])<br> strLastName = Nz(![LastName])<br> strSuffix = Nz(![Suffix])<br> strJobTitle = Nz(![JobTitle])<br> strLastNameFirst = Nz(![LastName]) & ", " & Nz(![FirstName])<br> strBusinessStreet = Nz(![BusinessStreet1]) & IIf(Nz(![BusinessStreet2]) <> "", strCRLF & Nz(![BusinessStreet2]), ""
<br> strBusinessCity = Nz(![BusinessCity])<br> strBusinessState = Nz(![BusinessState])<br> strBusinessPostalCode = Nz(![BusinessPostalCode])<br> strBusinessCountry = Nz(![BusinessCountry])<br> strBusinessPhone = Nz(![BusinessPhone])<br> strBusinessFax = Nz(![BusinessFax])<br> strHomeStreet = Nz(![HomeStreet1]) & IIf(Nz(![HomeStreet2]) <> "", strCRLF & Nz(![HomeStreet2]), ""
<br> strHomeCity = Nz(![HomeCity])<br> strHomeState = Nz(![HomeState])<br> strHomePostalCode = Nz(![HomePostalCode])<br> strHomeCountry = Nz(![HomeCountry])<br> strHomePhone = Nz(![HomePhone])<br> strHomeFax = Nz(![HomeFax])<br> strOtherStreet = Nz(![OtherStreet1]) & IIf(Nz(![OtherStreet2]) <> "", strCRLF & Nz(![OtherStreet2]), ""
<br> strOtherCity = Nz(![OtherCity])<br> strOtherState = Nz(![OtherState])<br> strOtherPostalCode = Nz(![OtherPostalCode])<br> strOtherCountry = Nz(![OtherCountry])<br> strOtherPhone = Nz(![OtherPhone])<br> strOtherFax = Nz(![OtherFax])<br> strEMailAddress = Nz(![E-mailAddress])<br> strEMailAddress2 = Nz(![E-mail2Address])<br> End With<br> <br> 'Create a contact item<br> Set itm = itms.Add("IPM.Contact"
<br> 'If desired, you can substitute the name of a custom form<br> 'for the standard Contact form, as below<br> 'Set itm = itms.Add("IPM.Contact.Custom Form"
<br> <br> With itm<br> .Title = strTitle<br> .FirstName = strFirstName<br> .MiddleName = strMiddleName<br> .LastName = strLastName<br> .Suffix = strSuffix<br> .JobTitle = strJobTitle<br> .BusinessAddressStreet = strBusinessStreet<br> .BusinessAddressCity = strBusinessCity<br> .BusinessAddressState = strBusinessState<br> .BusinessAddressPostalCode = strBusinessPostalCode<br> .BusinessAddressCountry = strBusinessCountry<br> .BusinessTelephoneNumber = strBusinessPhone<br> .BusinessFaxNumber = strBusinessFax<br> .HomeAddressStreet = strHomeStreet<br> .HomeAddressCity = strHomeCity<br> .HomeAddressState = strHomeState<br> .HomeAddressPostalCode = strHomePostalCode<br> .HomeAddressCountry = strHomeCountry<br> .HomeTelephoneNumber = strHomePhone<br> .HomeFaxNumber = strHomeFax<br> .OtherAddressStreet = strOtherStreet<br> .OtherAddressCity = strOtherCity<br> .OtherAddressState = strOtherState<br> .OtherAddressPostalCode = strOtherPostalCode<br> .OtherAddressCountry = strOtherCountry<br> .OtherTelephoneNumber = strOtherPhone<br> .OtherFaxNumber = strOtherFax<br> .Email1Address = strEMailAddress<br> .Email2Address = strEMailAddress2<br> .Categories = "From Access"<br> .Close (olSave)<br> Me![txtLastContact] = strContactID & " -- " & strLastNameFirst<br> DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70<br> End With<br> rst.MoveNext<br> Loop<br> <br> MsgBox "All Contacts exported!"<br> <br>Exit_cmdPushData_Click:<br> Exit Sub<br><br>Err_cmdPushData_Click:<br> MsgBox Err.Description<br> Resume Exit_cmdPushData_Click<br><br>End Sub<br><br>