Advertisement

03.14.2007 at 07:15PM PDT, ID: 22450610
[x]
Attachment Details

Nested for loop problem - VBA

Asked by ajslentz in Access Coding/Macros, Microsoft Access Database, SQL Query Syntax

Tags: vba, nested, loop

I have a small set of code which I just added a nested loop.  Basically the program will loop through multiple selections and get multiple records for each selection (the nested part).  I then need it to send an email for each record in the nested loop.  I can't seem to get it!  Any ideas?  I tried to note the nested part below.  This is something simple but my brain is fried!   Here is the code:

Private Sub cmdProcessInvCat_Click()
   
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim fs As Object
Dim strFrom As String, strTo As String, strFilename As String, strE As String, strYN As String
Dim txtDate As String, FileName As String, ClientNumber As String
Dim intCount As Integer, XONum As String, Message As String, strSQL As String

txtDate = Me.txtEOMDate.Value


Set db = CurrentDb
Set rs = db.OpenRecordset("tblFileList")
Set fs = CreateObject("Scripting.FileSystemObject")

intCount = 1
    For intCount = 1 To rs.RecordCount
        strFilename = rs.Fields(0) 'filename
        strFrom = rs.Fields(1) 'source directory
        strTo = rs.Fields(2) 'destination location
        strYN = rs.Fields(3) 'checkbox
       
        DoCmd.SetWarnings False
           
        If strYN = "True" Then
            FileName = txtDate & Left(strFilename, 10)
            ClientNumber = Right(FileName, 4)
            XONum = Mid(strFilename, 3, 4)
           
            If ClientNumber = "C156" Then
                strSQL = "Delete * from tblXOOrigC156"
                DoCmd.RunSQL (strSQL)
                'TEMP DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblXOOrigC156", strFrom & txtDate & "-" & strFilename, True, ""
                'Call Macro
                'TEMP DoCmd.RunMacro "mcrProcessC156"
                'Copy to new location
                'TEMP DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
                    "tblXOC156", strTo & txtDate & "_" & ClientNumber & "_XO" & XONum
                'Delete Table
                'TEMP DoCmd.DeleteObject acTable, "tblXOC156"
                GoTo EndSub
            End If
           
            If ClientNumber = "C150" Then
                strSQL = "Delete * from tblXOOrigC150"
                DoCmd.RunSQL (strSQL)
                'Import
                DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblXOOrigC150", strFrom & txtDate & "-" & strFilename, True, ""
                'Call Macro
                DoCmd.RunMacro "mcrProcessC150"
                'Copy to new location
                DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
                    "tblXOC150", strTo & txtDate & "_" & ClientNumber & "_XO" & XONum
                'Delete Table
                DoCmd.DeleteObject acTable, "tblXOC150"
                GoTo EndSub
           
            End If
           
            If ClientNumber = "C908" Then
                strSQL = "Delete * from tblXOOrigC908"
                DoCmd.RunSQL (strSQL)
                DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblXOOrigC908", strFrom & txtDate & "-" & strFilename, True, ""
                'Call Macro
                DoCmd.RunMacro "mcrProcessC908"
                DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
                    "tblXOC908", strTo & txtDate & "_" & ClientNumber & "_XO" & XONum
                'Delete Table
                DoCmd.DeleteObject acTable, "tblXOC908"
                GoTo EndSub
           
            End If

        End If
EndSub:

        MsgBox (XONum & "," & ClientNumber)
        Dim RS_Query As String, rs2 As DAO.Recordset, InvNumber As String, InvName As String
        Dim ReportLocation As String, email As String, FirstName As String, intCount2 As Integer
        Dim Investor As String, SmallClientNumber As String
       
        SmallClientNumber = Right(ClientNumber, 3)

        RS_Query = "SELECT tblInvList.InvNumber, tblInvList.InvName, " & _
                "tblInvList.ReportLocation, tblAssociates.[First Name], tblAssociates.Email " & _
                "FROM tblAssociates INNER JOIN tblInvList ON tblAssociates.ID = tblInvList.AssociateID " & _
                "WHERE tblInvList.ClientNo='" & SmallClientNumber & "' AND " & _
                "tblInvList.XONumber ='" & XONum & "'"

        Set rs2 = db.OpenRecordset(RS_Query)

PROBLEMS WITH THE NESTED FOR LOOP BELOW!!!
        intCount2 = 1
        For intCount2 = 1 To rs2.RecordCount
     
            InvNumber = Nz(rs2("InvNumber"), "")
            InvName = Nz(rs2("InvName"), "")
            ReportLocation = Nz(rs2("ReportLocation"), "")
            email = Nz(rs2("Email"), "")
            FirstName = Nz(rs2("First Name"), "")
            email = "Bob@Tom.com"

            strsubject = "Test"
            strMessage = "Test"
            rs2.MoveNext

        rs2.MoveNext
       Next
END NESTED FOR LOOP!!!    
    rs.MoveNext
    Next
   
DoCmd.SetWarnings True
MsgBox ("Process Complete.")
EndProgram:

End SubStart Free Trial
 
Loading Advertisement...
 
[+][-]03.14.2007 at 07:24PM PDT, ID: 18724239

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:26PM PDT, ID: 18724251

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:30PM PDT, ID: 18724257

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:33PM PDT, ID: 18724266

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:35PM PDT, ID: 18724273

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:37PM PDT, ID: 18724280

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:37PM PDT, ID: 18724281

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:40PM PDT, ID: 18724291

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:41PM PDT, ID: 18724300

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:42PM PDT, ID: 18724303

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:43PM PDT, ID: 18724309

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:44PM PDT, ID: 18724312

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:44PM PDT, ID: 18724313

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:44PM PDT, ID: 18724315

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:47PM PDT, ID: 18724321

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:48PM PDT, ID: 18724328

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:50PM PDT, ID: 18724336

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:52PM PDT, ID: 18724338

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Coding/Macros, Microsoft Access Database, SQL Query Syntax
Tags: vba, nested, loop
Sign Up Now!
Solution Provided By: capricorn1
Participating Experts: 3
Solution Grade: A
 
 
[+][-]03.14.2007 at 07:55PM PDT, ID: 18724348

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 07:58PM PDT, ID: 18724360

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:01PM PDT, ID: 18724372

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:04PM PDT, ID: 18724381

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:06PM PDT, ID: 18724387

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:07PM PDT, ID: 18724391

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:10PM PDT, ID: 18724403

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:11PM PDT, ID: 18724409

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.14.2007 at 08:12PM PDT, ID: 18724410

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:15PM PDT, ID: 18724418

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:17PM PDT, ID: 18724427

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:20PM PDT, ID: 18724436

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:21PM PDT, ID: 18724439

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.14.2007 at 08:34PM PDT, ID: 18724487

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32