Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Access > VBA Access
VBA Access Le forum pour les questions relatives au code VBA sous Access, et à son environnement de développement VBE.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/09/2011, 11h08   #1
Invité régulier
 
Inscription : mai 2006
Messages : 40
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 40
Points : 6
Points : 6
Par défaut VBA: ajout de l'adresse email destinataire

Bonjour à tous,

je cherche à améliorer le code suivant, destiné à reporter une facture dans un email. C'est une application Access.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
Public Function DescriptionTxt() As String
    Dim Txt As String
    Dim RS As Recordset
    Dim TotalVol As Long
 
    If IsNull(Me.IDCmd) Then
        DescriptionTxt = ""
        Exit Function
    End If
 
    Txt = Format(Me.IDEta.Column(2), ">") & vbCrLf & vbCrLf
    Txt = Txt & "Date : " & Format(Me.DateCmd, "dddd d mmmm yyyy") & vbCrLf
    Txt = Txt & "N/Réf. : " & Format(Me.NRef, "00-0000") & vbCrLf
    If Not IsNull(Me.NumPiece) Then Txt = Txt & "Pièce : " & Me.NumPiece & vbCrLf
    If Not IsNull(Me.VRef) Then Txt = Txt & "V/Réf. : " & Me.VRef & vbCrLf
    If Not IsNull(Me.VAT) Then Txt = Txt & "V/VAT : " & Me.VAT & vbCrLf
    Txt = Txt & vbCrLf & "________________________________________________________________" & vbCrLf & vbCrLf
    Txt = Txt & "ADRESSE" & vbCrLf & vbCrLf
    Txt = Txt & Me.Adresse & vbCrLf
    Txt = Txt & vbCrLf & "________________________________________________________________" & vbCrLf & vbCrLf
    Txt = Txt & "DETAIL DE LA COMMANDE" & vbCrLf
    Set RS = CurrentDb.OpenRecordset("SELECT Detail.IDDet, IIf(IsNull([IDCtg]),[IDLiv],[Categorie] & "" - "" & [Num]) AS Ref, Detail.Designation, Detail.NbVol, Detail.Prix FROM Detail LEFT JOIN Categorie ON Detail.IDCtg = Categorie.IDCat WHERE Detail.IDCmd = " & Me.IDCmd & " ORDER BY Detail.IDDet")
    TotalVol = 0
    Do While Not RS.EOF
        Txt = Txt & vbCrLf
        If Not IsNull(RS!Ref) Then Txt = Txt & RS!Ref & " : "
        Txt = Txt & RS!Designation & vbCrLf
        Txt = Txt & RS!NbVol & " vol. - " & Format(RS!Prix, "# ##0.00") & " EUR" & vbCrLf
        TotalVol = TotalVol + RS!NbVol
        RS.MoveNext
    Loop
    RS.Close
    Txt = Txt & vbCrLf & "________________________________________________________________" & vbCrLf & vbCrLf
    Txt = Txt & "RECAPITULATIF" & vbCrLf & vbCrLf
    Txt = Txt & TotalVol & " vol. - " & Format(Me.SousTotalAvant, "# ##0.00") & " EUR" & vbCrLf
    If Me.Remise <> 0 Then
        Txt = Txt & vbCrLf & "Remise : " & Format(Me.Remise, "# ##0.00") & " EUR" & vbCrLf
        Txt = Txt & vbCrLf & "______________________________________" & vbCrLf & vbCrLf
        Txt = Txt & "Sous-total : " & Format(Me.SousTotalApres, "# ##0.00") & " EUR" & vbCrLf
    End If
    Txt = Txt & vbCrLf & "Port et assurance : " & Format(Me.Port, "# ##0.00") & " EUR" & vbCrLf
    Txt = Txt & vbCrLf & "______________________________________" & vbCrLf & vbCrLf
    Txt = Txt & Format(Me.SousTotalFinal, "# ##0.00") & " EUR" & vbCrLf
    If (Me.Total + Me.Acompte - Me.TVA - Me.Port - Me.SousTotalApres) >= -1 Then
    Txt = Txt & vbCrLf & "TVA 4% : " & Format(Me.TotalTVA, "# ##0.00") & " EUR" & vbCrLf
    End If
    Txt = Txt & vbCrLf & "______________________________________" & vbCrLf & vbCrLf
 
    Txt = Txt & "TOTAL de votre commande : " & Format(Me.Total + Me.Acompte, "# ##0.00") & " EUR" & vbCrLf
If Me.TotalTVA > 0 Then
    Txt = Txt & vbCrLf & "dont TVA : " & Format(Me.TotalTVA, "# ##0.00") & " EUR" & vbCrLf
    End If
If Me.Acompte <> 0 Then
        Txt = Txt & vbCrLf & "Acompte déjà versé : " & Format(Me.Acompte, "# ##0.00") & " EUR" & vbCrLf
        Txt = Txt & "SOLDE restant à payer : " & Format(Me.Total, "# ##0.00") & " EUR" & vbCrLf
    End If
 
    Txt = Txt & vbCrLf & vbCrLf & vbCrLf & Me.Notes
    DescriptionTxt = Txt
End Function
Ce que je voudrais c'est que l'adresse email du destinaire soit insérée à sa place, à partir du champ Me.Email, dans l'email généré par la fonction. Ainsi on n'aurait plus qu'à envoyer l'email alors qu'actuellement il faut d'abord aller repêcher l'adresse email dans la fiche du client.

Merci d'avance pour vos suggestions
torobravo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/09/2011, 14h13   #2
Invité régulier
 
Inscription : mai 2006
Messages : 40
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 40
Points : 6
Points : 6
J'ai résolu le problème grâce à cette page décrivant la fonction SendObject utilisée pour envoyer un email à partir d'Access.

http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

Le code posté ci-dessus n'avait rien à voir avec l'envoi du message email mais concernait seulement l'élaboration de son contenu.

Mea maxima culpa.

Merci à tous ceux qui auront passé un moment à me lire.
torobravo est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 23h42.


 
 
 
 
Partenaires

Hébergement Web