SELECT Players.Surname, Players.[First Name], CCur([Weekly Attendances]![Attendances]*[Session Cost]![Price]) AS Total
FROM [Session Cost], Players INNER JOIN [Weekly Attendances] ON Players.EBU_Number = [Weekly Attendances].EBU_Number
WHERE ((([Weekly Attendances].Month)=[Forms]![frmInvoicesSent]![cboMonth]+[Forms]![frmInvoicesSent]![cboYear]))
ORDER BY Players.Surname;
Hi David,
If I look at your sql-string, then the only variable part is the Where-clause, and with that sql-string you want to export the data to an Excel-file.
You could write the sql-string as:
active_sql = "SELECT Players.Surname, Players.[First Name], CCur([Weekly Attendances]!Attendances]*[Session Cost]![Price]) AS Total FROM [Session Cost], Players INNER JOIN [Weekly Attendances] ON Players.EBU_Number = [Weekly Attendances].EBU_Number {WHERE} ORDER BY Players.Surname"
Now, when you replace the {WHERE} placeholder with the actual value, you have your dynamical sql-string.
On the form you can construct active_where (Me is the actual form):
active_where = " AND [Weekly Attendances].Month = " & As_text(Me!cboMonth + Me!cboYear)
I assume Month and Year are text-fields, but perhaps you have to change this to your real situation.
I start with " AND", because you can have many AND's concatenated, and only the first must be changed to " WHERE".
So: active_where = Replace (active_where, " AND", " WHERE", 1, 1)
And finally: active_sql = Replace (active_sql, "{WHERE}", active_where)
This dynamical string can be used to report to the Treasurer.
My real situation is a little more complex, because all parts of the sql-string are dynamical. This means that also forms (and reports) are dynamical.
Imb.