Hey all, Me again!
I have created this subroutine, and maybe I just don't understand loops well enough, but this is what I came up with and it is not working.
To summarize, I run an sql statement that retrieves some values and places them into an array.
i.e.
Record(0) = A
Record(1) = C
Record(2) = D
Then what I need to do, is assign values to my unbound text boxes on the report named rptTitle1, rptTitle2, rptTitle3, rptPage1, rptPage2, rptPage3 by looping through that array, pulling data out of a table based on each recordset, and assign for example rptTitle1 = "Holdings", rptPage1 = 1, rptTitle2 = "NetInvestment" , rptPage2 = 4.. I think, i hope, you can see where I am going with this. But my code, loops to many times, and the text boxes are not being assigned their values. My sub routine follows:
	Any help is GREATLY appreciated. I haven't touched anything related to VB in two years so it is hard for me to remember what to do...
							
						
					I have created this subroutine, and maybe I just don't understand loops well enough, but this is what I came up with and it is not working.
To summarize, I run an sql statement that retrieves some values and places them into an array.
i.e.
Record(0) = A
Record(1) = C
Record(2) = D
Then what I need to do, is assign values to my unbound text boxes on the report named rptTitle1, rptTitle2, rptTitle3, rptPage1, rptPage2, rptPage3 by looping through that array, pulling data out of a table based on each recordset, and assign for example rptTitle1 = "Holdings", rptPage1 = 1, rptTitle2 = "NetInvestment" , rptPage2 = 4.. I think, i hope, you can see where I am going with this. But my code, loops to many times, and the text boxes are not being assigned their values. My sub routine follows:
Code:
	Option Compare Database Option Explicit Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) Dim db As Database Dim rept As DAO.Recordset Dim Rcount As DAO.Recordset Dim T As DAO.Recordset Dim Report() As Variant Dim sql1 As String Dim sqlA As String Dim sqlB As String Dim i As Integer Dim l As Integer Dim R As String Dim Z As String Dim rptTitle As String Dim rptPage As String Dim pg As Integer Set db = CurrentDb pg = 1 ' Get list of report codes and place into an array sql1 = "Select rpt FROM scarlet WHERE rpt <> '~' GROUP BY rpt" Set rept = CurrentDb.OpenRecordset(sql1) rept.MoveLast rept.MoveFirst Report = rept.GetRows(rept.RecordCount) ' Loop through array of reports from table scarlet ' select recordset where array(0, i) = report title For i = 0 To rept.RecordCount - 1 For l = 1 To rept.RecordCount rptPage = "Me.rptPage" & l & "=" & pg MsgBox "The Number of Records = " & rept.RecordCount rptTitle = "Me.rptTitle" & l R = Report(0, i) sqlB = "select rpt_title from titles where code = " & "'" & R & "'" Set T = CurrentDb.OpenRecordset(sqlB) rptTitle = T.GetRows(T.RecordCount) sqlA = "select count(*) from scarlet where attribute = 'R' and rpt = " & "'" & R & "'" Set Rcount = db.OpenRecordset(sqlA) pg = pg + Rcount.Fields(0) + 1 Next l Next i End Sub
 
	
Comment