Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2006, 09:56 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re-Odering levels

Hi All
I am using the following code to re-oder Peripherals devices.The problem I am having is that if a I have two devices on order for the one company it sends two e-mails to the company.Is there anything I can add to the code to only send one e-mail.
Dim db As Database
    Dim recReOrder As Recordset
    Dim recSupps As Recordset
    Dim objOutlook As New Outlook.Application
    Dim objMessage As MailItem
    Dim strSQL As String
    Dim strOrder As String
    Dim strItems As String


    Set db = CurrentDb()
    Set recSupps = db.OpenRecordset("qryReOrderSuppliers")


    While Not recSupps.EOF

        strSQL = "SELECT * FROM qryReOrder WHERE fkCompanyID = " & recSupps("CompanyID")
        Set recReOrder = db.OpenRecordset(strSQL)


        strItems = "Item" & vbTab & "Quantity"
        While Not recReOrder.EOF
            strItems = strItems & vbCrLf & recReOrder("Name") & _
                                  vbTab & recReOrder("ReOrderPoint")
            recReOrder.MoveNext
        Wend

       strOrder = "Hi " & recSupps("ContactName") & _
            vbCrLf & vbCrLf & _
            "Once again we are running short of the following items:" & _
            vbCrLf & vbCrLf & _
            strItems & _
            vbCrLf & vbCrLf & _
            "I'd be grateful if you could deliver these as soon as possible." & _
            vbCrLf & vbCrLf & _
            "Many Thanks" & _
            vbCrLf & vbCrLf & _
            "Brendan"

        If Not IsNull(recSupps("Email")) Then
            Set objMessage = objOutlook.CreateItem(olMailItem)
            With objMessage
                .To = recSupps("Email")
                .Subject = ""
                .Body = strOrder
                .Send

            End With

        End If





        recSupps.MoveNext
    Wend


    recSupps.Close
    Set recSupps = Nothing
    Set recReOrder = Nothing
    Set objOutlook = Nothing


End Sub
Thanks


Brendan Bartley
__________________
Brendan Bartley
 
Old November 16th, 2006, 10:15 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   I can't see the fields in your query, but if you have dupes, remove fields until you only get a single entry for each vendor with an outstanding order. Perhaps you can create a query with vendors with outstanding orders, then create a second query that just looks up the Vendor name in the first query, and set the Unique Values property to Yes. That will pull only one vendor regardless of the number of outstanding orders.

   Once you have the vendor names, then package your email.

HTH

mmcdonal
 
Old November 16th, 2006, 11:41 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have

Brendan Bartley
 
Old November 16th, 2006, 11:42 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried your suggestions and it does not work
Thanks

Brendan Bartley
 
Old November 16th, 2006, 11:46 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am working on the same issue this morning to send emails to users who have more than one issue, but package all issues in a single email to each user.

I am doing the following:

Create a view showing me the individual users with issues, but just their names, and unique values, so users with issues are in the view (query) once, no matter how many issues they have.

Then create a view showing me the users, and their issues.

I loop through the first view
   Then, using one name at a time, I loop through the second view
     Then taking each issue for this one user, I package it into the email
        Then I email this user
     End If
   End If
Loop

You have to nest them like this, and have your emails send from the center of the nested loops.

HTH

mmcdonal
 
Old November 16th, 2006, 12:41 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Actually, I think you would do this:

Select Individual Company (rs1)
   Select All issues for Company (rs2)
     Capture those in a string variable like
       string = string & vbCrLf & rs2("Issue")
   rs2.MoveNext
   Loop
     If string <> "" Then
       Email function here
     End If
rs1.MoveNext
Loop



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
levels for the small stars crmpicco Forum and Wrox.com Feedback 2 December 5th, 2006 05:33 AM
Isolation Levels - Locking SQLScott SQL Server 2005 6 May 24th, 2006 11:59 AM
problem with access levels in application nav1 VB How-To 2 March 8th, 2005 05:17 PM
To tables combined to two levels jzac HTML Code Clinic 2 October 20th, 2004 04:20 PM
user levels dazednconfused Beginning PHP 3 July 8th, 2003 04:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.