The following VBA subroutine is the eventual solution:
Private Sub Export_Click() Dim whereClause As String ' Generate our WHERE clause based on form values whereClause = GenerateFilterClause ' If we have no filter, export nothing If IsEmptyString(Nz(whereClause)) Then Exit Sub End If Dim query As String query = "SELECT DISTINCTROW Contacts.* " & _ " FROM Contacts " & _ " INNER JOIN Applications " & _ " ON Contacts.ContactID = Applications.ContactID " & _ " WHERE " & whereClause & ";" Dim filename As String filename = "c:\test.xls" ' Placeholder query already in the database Dim queryName As String queryName = "FilterExportQuery" ' Update the placeholder with the created query CurrentDb.QueryDefs(queryName).SQL = query ' Run the export DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, queryName, filename End Sub
Brilliant ¡¡¡ , it was really helpful
ReplyDeleteThanks a lot
I am not very familiar with VBA. Could you go step by step as to how I would enter that into a Macro after you open up access and open up the table?
ReplyDeleteThank you!
Walt
@Walt - I'm not familiar with setting up a macro on the table itself. This example was tied to a button click on an Excel form I created. You might find this page useful.
ReplyDelete