I have a report that loops through multiple records to combine one field with multiple results into one record. The code is as follows:
I have the Code on the On Open event. The problem is the query that supplies this report ask for a specific Location Number so only that location pulls. Because the code runs first it does not have a Location number to allow the code to do what I need it to.
I hope this made sence.
Code:
Private Sub Report_Open(Cancel As Integer) Dim Loc_No As String Dim stLinkCriteria As String Dim rst As ADODB.Recordset Dim sLocation As String Dim strEmail As String sLocation = Me![Loc No] Set rst = New ADODB.Recordset rst.Open "SELECT Email " & _ "FROM tblContacts dc inner join tblContactsLocations dcl on dc.ID = dcl.ID " & _ "WHERE dcl.[Loc No] = '" & sLocation & "'", _ CurrentProject.Connection, adOpenForwardOnly Do Until rst.EOF strEmail = strEmail & rst("Email") & "; " rst.MoveNext Loop strEmail = Left(strEmail, Len(strEmail) - 2) rst.Close Set rst = Nothing End Sub
I hope this made sence.
Comment