Public Sub ImportGWContacts([red]myLogin[/red] As String, [red]myBookName[/red] As String)
Dim myApp As GroupwareTypeLibrary.Application2
Dim myAccount As GroupwareTypeLibrary.Account3
Dim myAddressBook As GroupwareTypeLibrary.AddressBook2
Dim myEntries As GroupwareTypeLibrary.AddressBookEntries2
Dim myFields As GroupwareTypeLibrary.Fields
Dim i As Integer
Dim x As Integer
Dim CurDB As DAO.Database
Dim Rst As DAO.Recordset
[green]'instantiate the GW object and login; set object variables[/green]
Set myApp = New GroupwareTypeLibrary.Application2
Set myAccount = myApp.Login(myLogin)
Set myAddressBook = myAccount.AddressBooks(myBookName)
Set myEntries = myAddressBook.AddressBookEntries
x = myAddressBook.AddressBookEntries.Count
[green]'open the contacts table[/green]
Set CurDB = CurrentDb()
Set Rst = CurDB.OpenRecordset("tblMyContacts")
If Not Rst.EOF Then
Rst.MoveLast
Rst.MoveFirst
End If
[green]'set the index for the Seek method[/green]
Rst.Index = "GWID"
[green]'loop through the selected address book[/green]
For i = 1 To x
Set myFields = myEntries(i).Fields
[green]'in this example, limit the scope to Novell Groupwise addresses[/green]
If myFields.Item("E-Mail Type", egwString) = "NGW" Then
With Rst
[green]'look for a matching GWID in contacts table; if not found, create a new record[/green]
.Seek "=", myFields.Item("User ID", egwString).Value
If .NoMatch Then
.AddNew
!GWID = myFields.Item("User ID", egwString).Value
!LastName = myFields.Item("Last Name", egwString).Value
!FirstName = myFields.Item("First Name", egwString).Value
!PhoneNumber = myFields.Item("Office Phone Number", egwString).Value
!Department = myFields.Item("Department", egwString).Value
!Email = myFields.Item("E-Mail Address", egwString).Value
.Update
End If
.MoveFirst
End With
End If
Next i
[green]'Close the recordset and release variables[/green]
Rst.Close
Set CurDB = Nothing
Set myFields = Nothing
Set myEntries = Nothing
Set myAddressBook = Nothing
Set myAccount = Nothing
Set myApp = Nothing
End Sub