scubadiver007
Registered User.
- Local time
- Today, 11:18
- Joined
- Nov 30, 2010
- Messages
- 317
Hi
I work as a performance data analyst in local government and report from a system called E-start which is used by children centre administrators to record attendees at their events.
One of the reports is for event outcomes. Each of these outcomes are compiled into a single field and separated by a full stop so I can do text-to-columns in Excel and then set up a link table.
For each record there can be anything from one outcome to over 20 though I don't think there would ever be more than 30.
I want to put all these outcomes into a single field. I could create 30 append queries but I thought it might be better to loop a query definition.
The field names would be AO1...AO30 (and I've set up a table if this helps).
In theory I could stop the loop when I get the first column that returns no records.
I've done something similar where I have used a loop to filter a query but not to change the field name.
I work as a performance data analyst in local government and report from a system called E-start which is used by children centre administrators to record attendees at their events.
One of the reports is for event outcomes. Each of these outcomes are compiled into a single field and separated by a full stop so I can do text-to-columns in Excel and then set up a link table.
For each record there can be anything from one outcome to over 20 though I don't think there would ever be more than 30.
I want to put all these outcomes into a single field. I could create 30 append queries but I thought it might be better to loop a query definition.
The field names would be AO1...AO30 (and I've set up a table if this helps).
In theory I could stop the loop when I get the first column that returns no records.
I've done something similar where I have used a loop to filter a query but not to change the field name.
Code:
Dim Email As String
Dim Kcode As String
Dim Qtr As String
Dim Kcodestr As String
Dim strSql As String
Dim mySql As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Qtr = Me!Quarter_ID
strSql = "SELECT DISTINCT Tble_Activity.Kcode, Tble_Practice.Email " & _
"From Tble_Practice INNER JOIN Tble_Activity ON Tble_Practice.Kcode = Tble_Activity.Kcode " & _
"WHERE ((Tble_Activity.Quartercode)=eval('[forms]![menu]!Quarter_ID'));" '& _
'"AND ((Tble_Activity.Kcode)=('J82054'));"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSql)
rs.MoveFirst
Do While Not rs.EOF
mySql = "SELECT PAYMENTS_Checks_src.Services, PAYMENTS_Checks_src.Total FROM PAYMENTS_Checks_src " & _
"WHERE PAYMENTS_Checks_src.KCode= '" & rs("KCode") & "'" & _
"AND ((PAYMENTS_Checks_src.Quartercode)=([forms]![menu]![Quarter_ID]));"
db.QueryDefs("Payments_KCode").SQL = mySql
Kcodestr = rs!Kcode
DoCmd.OutputTo acOutputQuery, "Payments_KCode", acFormatXLS, "I:\Medical\Enhanced Services\ENHANCED SERVICES\2013-2014\payments\" & Qtr & "\" & Kcodestr & " " & Qtr & " - payments.xls"
rs.MoveNext
Loop