Solved

Defining variables and Send Object method

Posted on 2004-10-04
2
152 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

21 Experts available now in Live!

Get 1:1 Help Now