header image

Makro: Uvozi podatke iz zbirke podatkov v Outlook

Združljivost VB/VBA ADODB & Outlook 2003/2007
Prispevek / Article Uvozimo podatke o kontaktih iz Birokrata v Outlook
Opis / Summary

Funkcija iz podatkovne zbirke prebere podatke o kontaktnih osebah in jih primerja s podatki o kontaktih v Outlooku, ter spremeni tiste, ki se razlikujejo od tistih v zbirki podatkov.

Function reads data from contacts database and compares them to those found in Outlook database. It updates Outlook contacts if it differs from those found in database.

Odvisnosti / Dependencies Funkcija/function: MiniDB
Funkcija/function: SQL
Public Sub Import()
On Error GoTo ErrorHandler

  Dim oItems As Outlook.items
  Dim oFolder As Outlook.folder
  Dim oContact As Outlook.ContactItem
  Dim oProp As Outlook.ItemProperty
  Dim oRS As ADODB.Recordset
  Dim oField As ADODB.Field
  Dim aFilter As String
  Dim fSave As Boolean

  Set oRS = New Recordset
  With oRS
    .ActiveConnection = DBUti.MiniDB("contacts")
    .Open DBUti.SQL("contacts", "select")
    .MoveFirst
  End With

  Do While Not oRS.EOF
    aFilter = "[CustomerID]='{0}'"
    aFilter = Replace(aFilter, "{0}", oRS.Fields("CustomerID").Value)

    Set oFolder = Session.GetDefaultFolder(olFolderContacts)
    Set oItems = oFolder.items
    Set oItems = oItems.Restrict(aFilter)

    If oItems.Count > 0 Then
      Set oContact = oItems.GetFirst
    Else
      Set oContact = Outlook.Application.CreateItem(olContactItem)
    End If

    For Each oField In oRS.Fields
      Set oProp = oContact.ItemProperties(oField.Name)
      If (CStr(oProp.Value) <> CStr(oField.Value)) Then
        oProp.Value = oField.Value
        fSave = True
      End If
    Next

    If fSave Then oContact.Save: fSave = False
    oRS.MoveNext
    DoEvents
  Loop

  oRS.Close

FinalHandler:
  Set oContact = Nothing
  Set oProp = Nothing
  Set oRS = Nothing
  Exit Sub

ErrorHandler:
  MsgBox Err.Description, vbOKOnly + vbExclamation, _
    "[Contact.Import] Napaka: " & Err.Number
  Resume FinalHandler

End Sub
http://office.blog.siol.net/primeri/makro-preberi-sql-stavek-iz-xml-datoteke/
  • Share/Bookmark

Pustite komentar

Tvoj odziv :

Komentiranje iz tujine je omogočeno zgolj prijavljenim uporabnikom !