Hi,
I was wondering if anyone knows whether or not there's a way to code something in VBA that would export whichever query is listed in the form's record source property to Excel.
In general, I know how to do all of that - typically I would do something along the lines of the below. For this, assume that the code is behind the "OnClick" property for a button on a form. The form is bound to "qry_MyData1" - thus if you go into the form properties, "qry_MyData1" would be listed under 'Record Source'.
So what I'm asking is whether the above could be tweaked to simply refer to the Record Source of the form, as opposed to explicitly listing out the query name (in a string variable, as I did in the above).Code:Dim strQuery As String Dim strFileName As String strQuery = "qry_MyData1" strFileName = strQuery & ".xlsx" DoCmd.OutputTo acOutputQuery, strQuery, acFormatXLSX, strFileName, True
Obviously it would only pertain to forms bound to a table or query in the DB, but that's essentially what I'm looking to do.
Any help would be appreciated. Thanks!