Hi David,
The error you get is because you use the active_sql as the name of a query. Alas, there is no such a query.
But there are more remarks: the sql-string does not contain the actual (variable) values but the verbatim control names.
Lets us go back to the beginning.
Of the form frmInvoicesSent you have the comboboxes to select Month and Year (because it is the active form you can use Me).
On that form you have also a command button to trigger the export.
In the Click event of that button you have the code that must be executed.
First you (or I) need to know what datatype is [Weekly Attendances].Month? This must exactly match Me!cboMonth + Me!cboYear. If you need "102024" or "1024" for the current month, the datatype is a String, and thus must be enclosed in single quotes.
To add these quotes, you can use the function As_text (see later).
Suppose the command button is called "Treasurer".
A very simple code could look like:
Sub Treasurer_Click()
Dim active_sql As String
Dim active_where As String
active_sql = "SELECT (Players ... ... ON Players.EBU_number = [Weekly Attendances].EBU_number) {WHERE} ORDER BY Players.Surname"
active_where = " AND [Weekly Attendances] = " & As_text(Me!cboMonth & Me!cboYear)
'now construct the final active_sql
active_where = Replace(active_where, " AND", " WHERE", 1, 1)
active_sql = Replace(active_sql, "{WHERE}", active_where)
'For further processing can use the function ExportToExcel that Ken supplied.
ExportToExcel active_sql, "C:\Documents\Invoices\Invoices Sent.xlsx"
End Sub
This is the basis, perhaps there is a typo somewhere.
If you understand how it works, you can nuanciate at will.
Finally the function As_text:
Function As_text(cur_text As String) As String
As_text = "'" & Replace(cur_text, "'", "''") & "'"
End Function
Place both functions As_text and ExportToExcel in a general module.
Success!
Imb.