Save Filter as a Query

dgaller

Registered User.
Local time
Yesterday, 20:12
Joined
Oct 31, 2007
Messages
60
I have a DB that I use a form filter in and would like to save the filter so the data can be exported. I originally used the export in the filter tool bar but the problem there is if columns are hidden they do not export and I need this user proof so the data can be changed and imported from excel.

Currently, I have this currently set up like:

DoCmd.Close acForm, "Stand by Message"
SendKeys "Task Detail Filter Export", False
SendKeys "{Enter}", False
DoCmd.RunCommand acCmdSaveAsQuery
DoCmd.Minimize
DoCmd.OutputTo acQuery, "Task Detail Filter Export 2", "MicrosoftExcelBiff8(*.xls)", "", False, "", 0
DoCmd.OpenForm "Task Detail Filter", acNormal, "", "", , acNormal
DoCmd.RunCommand acCmdFilterByForm
DoCmd.DeleteObject acQuery, "Task Detail Filter Export"


But using the send keys does not always work as smooth as I would like.

Is there a way I can eliminate the send Keys and automatically assign the Query name in the DoCmd.RunCommand acCmdSaveAsQuery Line?
 
i wouldnt suggest waiting till form close and applying all circus loops above mind you a form filter isnt exactly a query but just an additional where close to a query ;)
now let me see how to work your problem in a way that is more calm.
ah yes :
in whichever event you change form filter add the following code :

Code:
If Not IsNull(Form.Filter) Then
 
Dim stCS, stSQL
 
If Right(Form.ControlSource,1) = ";" Then ' Find If Source Is A Query Or Table
   stCS = Left(Form.ControlSource, Len(Form.ControlSource)-1)  ' If Query Remove ;
Else
   stCS = "Select * From " & Form.ControlSource ' If Table Generate Sub Select Statment
End If
 
stSQL = "Select * From (" & stCS & ") As Table1 Where " & Form.Filter & ";"  ' Generate Virtual Query Statment
 
CurrentDb.CreateQueryDef "QueryNameHere", stSQL ' Create Query
End if
 

Users who are viewing this thread

Back
Top Bottom