Mini client notes ecrit en vb5 !

Description

Démonstration de l'utilisation des object COM de Lotus Notes. (Version 5 minimum) pour faire un petit "client" Notes en VB5 (lecture et affichage des message reçu)

Merci à Oguruma, modérateur de www.dominoarea.org (Forum Lotus Notes en Français)

Source / Exemple :


VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5580
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6885
   LinkTopic       =   "Form1"
   ScaleHeight     =   5580
   ScaleWidth      =   6885
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton CmdMove 
      Caption         =   "Move To"
      Enabled         =   0   'False
      Height          =   375
      Left            =   5880
      TabIndex        =   10
      Top             =   120
      Width           =   855
   End
   Begin VB.TextBox Folder 
      Height          =   375
      Left            =   3240
      TabIndex        =   9
      Top             =   120
      Width           =   2655
   End
   Begin VB.CommandButton CmdLast 
      Caption         =   ">> |"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2280
      TabIndex        =   8
      Top             =   120
      Width           =   615
   End
   Begin VB.CommandButton CmdNext 
      Caption         =   ">"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1560
      TabIndex        =   7
      Top             =   120
      Width           =   615
   End
   Begin VB.CommandButton CmdPrevious 
      Caption         =   "<"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   840
      TabIndex        =   6
      Top             =   120
      Width           =   615
   End
   Begin VB.TextBox From 
      Height          =   375
      Left            =   1200
      Locked          =   -1  'True
      TabIndex        =   3
      Top             =   1080
      Width           =   5535
   End
   Begin VB.CommandButton cmdFirst 
      Caption         =   "| <<"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   2
      Top             =   120
      Width           =   615
   End
   Begin VB.TextBox Body 
      Height          =   3855
      Left            =   120
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   1
      Top             =   1560
      Width           =   6615
   End
   Begin VB.TextBox subject 
      Height          =   375
      Left            =   1200
      Locked          =   -1  'True
      TabIndex        =   0
      Top             =   720
      Width           =   5535
   End
   Begin VB.Label Label 
      Alignment       =   1  'Right Justify
      BackStyle       =   0  'Transparent
      Caption         =   "De :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   1
      Left            =   240
      TabIndex        =   5
      Top             =   1080
      Width           =   855
   End
   Begin VB.Label Label 
      Alignment       =   1  'Right Justify
      BackStyle       =   0  'Transparent
      Caption         =   "Sujet :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   4
      Top             =   720
      Width           =   855
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'-----------------------------------------------------------------------------
' (C)2005 by Patrick MOIRE
'------------------------------------------------------------------------------
' DEMO UTILISATION DES OBJETS COM de Lotus Notes
'
' Merci à Oguruma, modérateur de www.dominoarea.org (Forum Lotus Notes en Français)

  Private session As New NotesSession
  Private dir As NotesDbDirectory
  Private db As NotesDatabase
  Private View As NotesView
  Private doc As NotesDocument

'------------------------------------------------------------------------------------
' Connection a Lotus Notes
'------------------------------------------------------------------------------------

Private Sub Form_Paint()

  Me.AutoRedraw = True
  DoEvents
  
  Me.Caption = "Connexion en cours..."
  
  session.Initialize
 ' PS : en cas de problème, remplacer par :
 '
 ' session.Initialize "password"
 '
 ' voir :
 '
 ' session.InitializeUsingNotesUserName "User", "password"
 '
   
  Set dir = session.GetDbDirectory("")
  Set db = dir.OpenMailDatabase
  
  Me.Caption = db.filename
  
  Set View = db.GetView("($inbox)")
  Me.Caption = db.filename & " : " & View.Name
  
  Call cmdFirst_Click

End Sub
  
  
'------------------------------------------------------------------------------------
' Déplacement dans la liste des couriers
'------------------------------------------------------------------------------------

Private Sub cmdFirst_Click()
  Set doc = View.GetFirstDocument
  Me.CmdNext.Enabled = (Not doc Is Nothing)
  Me.CmdPrevious.Enabled = False
  Call Affiche
End Sub

Private Sub CmdPrevious_Click()
  If Not doc Is Nothing Then
    Set doc = View.GetPrevDocument(doc)
    Me.CmdNext.Enabled = True
    Me.CmdPrevious.Enabled = Not (View.GetPrevDocument(doc) Is Nothing)
  End If
  Call Affiche
End Sub

Private Sub CmdNext_Click()
  If Not doc Is Nothing Then
    Set doc = View.GetNextDocument(doc)
    Me.CmdPrevious.Enabled = True
    Me.CmdNext.Enabled = Not (View.GetNextDocument(doc) Is Nothing)
  End If
  Call Affiche
End Sub

Private Sub CmdLast_Click()
  Set doc = View.GetLastDocument
  Me.CmdNext.Enabled = False
  Call Affiche
End Sub

  
'------------------------------------------------------------------------------------
' Affichage d'un courier
'------------------------------------------------------------------------------------

Private Sub Affiche()

  Me.CmdMove.Enabled = (Not doc Is Nothing)
  Me.cmdFirst.Enabled = Me.CmdPrevious.Enabled
  Me.CmdLast.Enabled = Me.CmdNext.Enabled
  
  Me.subject.Text = ""
  Me.From.Text = ""
  Me.Body.Text = ""

  If Not doc Is Nothing Then
    If doc.HasItem("subject") Then Me.subject.Text = doc.GetItemValue("subject")(0)
    If doc.HasItem("from") Then Me.From.Text = doc.GetItemValue("from")(0)
    If doc.HasItem("body") Then Me.Body.Text = doc.GetItemValue("body")(0)
  End If
  
End Sub

'------------------------------------------------------------------------------------
' Deplacement d'un document dans un "folder"
'------------------------------------------------------------------------------------

Private Sub CmdMove_Click()
  moveToFolder db, doc, Me.Folder.Text
End Sub

Function moveToFolder(dbMailbox As NotesDatabase, docMailbox As NotesDocument, folderName As String) As Boolean
  Dim docMailBoxCopy As NotesDocument
    On Error GoTo handleError
      Set docMailBoxCopy = docMailbox.CopyToDatabase(dbMailbox)
      docMailBoxCopy.PutInFolder folderName, True
      docMailbox.Remove True
    On Error GoTo 0
    moveToFolder = True
    Exit Function
handleError:
  MsgBox "Error # " & Err & " : " & Error$ & " - line " & Erl, 16, "DEMOA Notes Error - moveToFolder"
End Function

'------------------------------------------------------------------------------------
' Déconnection de Lotus Notes
'------------------------------------------------------------------------------------

Private Sub Form_Unload(Cancel As Integer)
  Set doc = Nothing
  Set View = Nothing
  Set db = Nothing
  Set dir = Nothing
  Set session = Nothing
End Sub

Conclusion :


Allez... j'en profite pour mettre un code pour envoyer un email via Notes. Pas de moi, mais fait un bon complément à mon code !

Private Sub Send()

Dim session As Object
Dim db As Object
Dim doc As Object

Set session = CreateObject("Notes.NotesSession")
Set db = session.GetDatabase("", "")
Call db.OPENMAIL

Set doc = db.CreateDocument()
With doc
.Form = "Memo"
.SendTo = "adresse@serveur.com"
.CopyTo = "adresse@serveur.com"
.subject = "Petit test"
.Body = "Ceci est un petit test d'envoie de message"
.From = session.CommonUserName
.PostedDate = Now
.SaveMessageOnSend = True
End With
Call doc.Send(True)

Set session = Nothing
Set db = Nothing
Set doc = Nothing

End Sub

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.