Hi
I wish to automate the detachment of email attachments from ny Notes (Version 5.08) to a given path.
I am using Access 97 VBA to access the Domino COM on NT.
The code below errors ("Object variable or with variable not set" at the indicated line.
Any ideas anyone?
Many thanks
Klopper
Public COMSess As Domino.NotesSession
Public COMDB As Domino.NotesDatabase
Public Sub NotesSaveAttachs(sPathToSave As String)
Dim View As New Domino.NotesView
Dim nDoc As Domino.NotesDocument
Set View = COMDB.GetView("($Inbox)" 'ERRORS HERE
Set nDoc = View.GetFirstDocument
Dim itm As Variant
While Not (nDoc Is Nothing)
If nDoc.HasEmbedded Then
Set itm = nDoc.GetFirstItem("Body"
If itm.Type = RICHTEXT Then
Dim attch As Variant
For Each attch In itm.EmbeddedObjects
If (attch.Type = EMBED_ATTACHMENT) Then
attch.ExtractFile sPathToSave & attch.Name
End If
Next
End If
' Following code commented is used to delete mails after
' attachments were saved to disk.
'Set nDoc2Remove = nDoc
End If
Set nDoc = View.GetNextDocument(nDoc)
' Following code commented is used to delete mails after
' attachments were saved to disk.
'If Not (nDoc2Remove Is Nothing) Then
' nDoc2Remove.Remove (True)
' Set nDoc2Remove = Nothing
'End If
Wend
End Sub
Public Sub OpenSess()
' Creates new Notes session object and prompt user to
' enter servername, password and database mail.
' Prompt for password can be override if you pass password value
' as parameter of initialize method.
' This could be stored on registry/ini file to ask the
' user only the first time.
' I used inputbox for easy, you could add a form to get all
' values.
Set COMSess = New Domino.NotesSession
COMSess.Initialize InputBox$("Please enter Database password.", "Enter Password"
Set COMDB = COMSess.GetDatabase(InputBox$("Please enter Domino server name here.", "Server name", "DOMINO_SERVER", _
InputBox$("Please enter Domino database name here.", "Enter database name", "\mail\7\mydb.nsf", _
False)
With COMDB
If Not .IsOpen Then
MsgBox "Unable to open Notes session.", vbCritical, "Init Error"
Set COMDB = Nothing
Set COMSess = Nothing
Exit Sub
Else
Dim f As String
f = BrwFolder
If f <> "" Then
NotesSaveAttachs f
Else
MsgBox "No directory was selected. Aborting", vbCritical, "Error"
End If
End If
End With
End Sub
Public Function BrwFolder() As String
Dim bi As BROWSEINFO
Dim pidl As Long
Dim path As String
Dim pos As Integer
'Fill the BROWSEINFO structure with the
'needed data. To accomodate comments, the
'With/End With sytax has not been used, though
'it should be your 'final' version.
'hwnd of the window that receives messages
'from the call. Can be your application
'or the handle from GetDesktopWindow().
bi.hOwner = 0 'Me.hWnd
'Pointer to the item identifier list specifying
'the location of the "root" folder to browse from.
'If NULL, the desktop folder is used.
bi.pidlRoot = 0&
'message to be displayed in the Browse dialog
bi.lpszTitle = "Select your Folder"
'the type of folder to return.
bi.ulFlags = BIF_RETURNONLYFSDIRS
'show the browse for folders dialog
pidl = SHBrowseForFolder(bi)
'the dialog has closed, so parse & display the
'user's returned folder selection contained in pidl
path = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal pidl, ByVal path) Then
pos = InStr(path, Chr$(0))
BrwFolder = Left$(path, pos - 1) & "\"
End If
Call CoTaskMemFree(pidl)
End Function
Sub NotesCloseSession()
' if version is 4.x there is another approach.
Set COMDB = Nothing
Set COMSess = Nothing
End Sub
I wish to automate the detachment of email attachments from ny Notes (Version 5.08) to a given path.
I am using Access 97 VBA to access the Domino COM on NT.
The code below errors ("Object variable or with variable not set" at the indicated line.
Any ideas anyone?
Many thanks
Klopper
Public COMSess As Domino.NotesSession
Public COMDB As Domino.NotesDatabase
Public Sub NotesSaveAttachs(sPathToSave As String)
Dim View As New Domino.NotesView
Dim nDoc As Domino.NotesDocument
Set View = COMDB.GetView("($Inbox)" 'ERRORS HERE
Set nDoc = View.GetFirstDocument
Dim itm As Variant
While Not (nDoc Is Nothing)
If nDoc.HasEmbedded Then
Set itm = nDoc.GetFirstItem("Body"
If itm.Type = RICHTEXT Then
Dim attch As Variant
For Each attch In itm.EmbeddedObjects
If (attch.Type = EMBED_ATTACHMENT) Then
attch.ExtractFile sPathToSave & attch.Name
End If
Next
End If
' Following code commented is used to delete mails after
' attachments were saved to disk.
'Set nDoc2Remove = nDoc
End If
Set nDoc = View.GetNextDocument(nDoc)
' Following code commented is used to delete mails after
' attachments were saved to disk.
'If Not (nDoc2Remove Is Nothing) Then
' nDoc2Remove.Remove (True)
' Set nDoc2Remove = Nothing
'End If
Wend
End Sub
Public Sub OpenSess()
' Creates new Notes session object and prompt user to
' enter servername, password and database mail.
' Prompt for password can be override if you pass password value
' as parameter of initialize method.
' This could be stored on registry/ini file to ask the
' user only the first time.
' I used inputbox for easy, you could add a form to get all
' values.
Set COMSess = New Domino.NotesSession
COMSess.Initialize InputBox$("Please enter Database password.", "Enter Password"
Set COMDB = COMSess.GetDatabase(InputBox$("Please enter Domino server name here.", "Server name", "DOMINO_SERVER", _
InputBox$("Please enter Domino database name here.", "Enter database name", "\mail\7\mydb.nsf", _
False)
With COMDB
If Not .IsOpen Then
MsgBox "Unable to open Notes session.", vbCritical, "Init Error"
Set COMDB = Nothing
Set COMSess = Nothing
Exit Sub
Else
Dim f As String
f = BrwFolder
If f <> "" Then
NotesSaveAttachs f
Else
MsgBox "No directory was selected. Aborting", vbCritical, "Error"
End If
End If
End With
End Sub
Public Function BrwFolder() As String
Dim bi As BROWSEINFO
Dim pidl As Long
Dim path As String
Dim pos As Integer
'Fill the BROWSEINFO structure with the
'needed data. To accomodate comments, the
'With/End With sytax has not been used, though
'it should be your 'final' version.
'hwnd of the window that receives messages
'from the call. Can be your application
'or the handle from GetDesktopWindow().
bi.hOwner = 0 'Me.hWnd
'Pointer to the item identifier list specifying
'the location of the "root" folder to browse from.
'If NULL, the desktop folder is used.
bi.pidlRoot = 0&
'message to be displayed in the Browse dialog
bi.lpszTitle = "Select your Folder"
'the type of folder to return.
bi.ulFlags = BIF_RETURNONLYFSDIRS
'show the browse for folders dialog
pidl = SHBrowseForFolder(bi)
'the dialog has closed, so parse & display the
'user's returned folder selection contained in pidl
path = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal pidl, ByVal path) Then
pos = InStr(path, Chr$(0))
BrwFolder = Left$(path, pos - 1) & "\"
End If
Call CoTaskMemFree(pidl)
End Function
Sub NotesCloseSession()
' if version is 4.x there is another approach.
Set COMDB = Nothing
Set COMSess = Nothing
End Sub