alsoascientist
Registered User.
- Local time
- Today, 22:52
- Joined
- Mar 26, 2012
- Messages
- 39
Hi All,
I am trying to create a new query through VBA that will take the SQL as a string for the fields and values required. This will create a query that will then be exported to excel.
This is a combination of a few codes that work fine themselves, however I don't seem to be able to figure out this last part! The eventual goal is to be able to export filtered data from a subform (filtered from the parent searchform) with a number of rows hidden (from checkboxes on the parent) and to remove the hidden columns and unwanted data on export.
The export works fine with just the filtered data, it's the hidden columns part I am having issues with. So far I have this:
Any ideas would be appreciated.
I am trying to create a new query through VBA that will take the SQL as a string for the fields and values required. This will create a query that will then be exported to excel.
This is a combination of a few codes that work fine themselves, however I don't seem to be able to figure out this last part! The eventual goal is to be able to export filtered data from a subform (filtered from the parent searchform) with a number of rows hidden (from checkboxes on the parent) and to remove the hidden columns and unwanted data on export.
The export works fine with just the filtered data, it's the hidden columns part I am having issues with. So far I have this:
Code:
Private Sub ExportBtn_Click()
On Error GoTo errHandler
Dim qdf As QueryDef
Me.[SearchSubForm].Form.RecordSource = BuildRept & " FROM " & "AllQuery" & BuildFilter
'BuildRept builds the SELECT part of the SQL, AllQuery is FROM and BuildFilter creates the WHERE - these all work fine individually
DoCmd.DeleteObject acQuery, "qryTemp"
Set qdf = CurrentDb.CreateQueryDef("qryTemp", Me.[SearchSubForm].Form.RecordSource)
DoCmd.OutputTo acOutputQuery, "qryTemp", acFormatXLS, , True
exitHandler:
Exit Sub
errHandler:
If Err.Number = 7874 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
Resume exitHandler
End If
End Sub
Any ideas would be appreciated.
Last edited: