Solved

Defining variables and Send Object method

Posted on 2004-10-04
2
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

738 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