Solved

Defining variables and Send Object method

Posted on 2004-10-04
2
153 Views
Last Modified: 2010-05-02
hi,

I have the following piece of code which I am using to act on a recordset in MS Access.  It basicaly sums the individual expense claims made by employees taht are paid on a certain data and generates an e-mail to these employees with a breakdown of their expenses  and the total amount paid.  I have the following problems:

1)  The d Total amount:  I always want this to display two two decimal places and a comma separator for thousands.  At the moment if there is say just the one expenses claim for a particual remployee of  say £19,200.00, then the total will be shown as £19200.  How do I change this?

2)  At the moment the e-mails are just sent from my Outlook Today mailbox.  However I have several mailboxes set up in my outlook and I'd like the e-mails to be sent from one of these other mailboxes - how do I build that into the code.

Grateful for all suggestions!

Thanks,

Andrew

Public Function SendAutoEmailUK1FIX() As Boolean

    Dim rs As DAO.Recordset
    Dim db As Database
    Dim strBODY As String
    Dim sSubject As String
    Dim sLastEmailAddr As String
    Dim sCurrEmailAddr As String
    Dim dTotal As Double
    Dim sPaymentDate As String

    On Error GoTo SMError

    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT EmailAddr,SheetNo,PaymentDate,PERSONAL_REFERENCE,AMOUNT, ZOINKS FROM tblEmailsUK1")         'We open a recordset, read all the emails
    sSubject = "Expenses Payment Remittance Advice - " & rs!PERSONAL_REFERENCE
   
    sLastEmailAddr = ""
    sPaymentDate = ""
    dTotal = 0
   
    'Loop
    Do While Not rs.EOF

        'Make a note of current email addr
        sCurrEmailAddr = rs!EmailAddr
       
        'If last email address differs to current email address
        'Note we check for not null 'cos first time in loop it will differ
        If sLastEmailAddr <> "" And sLastEmailAddr <> sCurrEmailAddr Then
       
            'Okay, change of email address, lets send the email address
            strBODY = "This e-mail is to notify you that on " & sPaymentDate & " a BACS transfer was made on your behalf to reimburse you for the expense claims listed below.  Please allow three working days from this date, inclusive, for the money to credit your bank account." & vbCrLf & vbCrLf & "Please note that details of your expenses are available on your KnowledgeNet home page.  Any queries should be directed to your practice administrator." & vbCrLf & strBODY & vbCrLf & vbCrLf & "Total Amount Paid GBP £" & dTotal
           
            SendMsg sLastEmailAddr, sSubject, strBODY
           
            'reset
            sLastEmailAddr = rs!EmailAddr
            sPaymentDate = rs!PaymentDate   'Store payment date of last email address
            dTotal = 0
            strBODY = ""
           
        End If
       
        'Build Body text, one line reading in ref and amount
        strBODY = strBODY & vbCrLf & "Sheet No: " & rs!SheetNo & vbTab & "Amount: " & rs!Amount & "      " & rs!ZOINKS
       
        dTotal = dTotal + rs!Amount
       
        sLastEmailAddr = sCurrEmailAddr
        sPaymentDate = rs!PaymentDate   'Store payment date of last email address
       
        'Move to next record
        rs.MoveNext
       
        'Check for eof - if so, send off the last lot
        If rs.EOF = True Then

            strBODY = "This e-mail is to notify you that on " & sPaymentDate & " a BACS transfer was made on your behalf to reimburse you for the expense claims listed below.  Please allow three working days from this date, inclusive, for the money to credit your bank account." & vbCrLf & vbCrLf & "Please note that details of your expenses are available on your KnowledgeNet home page.  Any queries should be directed to your practice administrator." & vbCrLf & strBODY & vbCrLf & vbCrLf

            strBODY = strBODY & vbCrLf & vbCrLf & "Total Amount Paid GBP £ " & dTotal
            SendMsg sCurrEmailAddr, sSubject, strBODY
        End If
    Loop
   
    'Close and clear all
    rs.Close
    Set rs = Nothing
    Set db = Nothing

    SendAutoEmail6 = True
    Exit Function

SMError:
    MsgBox "A problem occurred." & vbCrLf & Err.Description, vbCritical, "Send Auto EMails"
    SendAutoEmails6 = False
End Function


Private Sub SendMsg(ByVal sAddr As String, ByVal sSubject As String, ByVal sBody As String)
Debug.Print "Sending Email to" & sAddr
    DoCmd.SendObject acSendNoObject, , , sAddr, , , sSubject, sBody, -1
End Sub
0
Comment
Question by:AndrewMcLaughlin
2 Comments
 
LVL 3

Accepted Solution

by:
sgayatri earned 500 total points
ID: 12216188
s=19200
str1=cstr(s)
msgbox format(str1,"00,000.00")
will get the proper format you need

shall get back to u later for your second question
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now