OutputTo filter or alternative

jambo

Access Lord
Local time
Tomorrow, 06:38
Joined
Oct 30, 2006
Messages
5
Hi, newbie here at the forums. I have used VB a bit, but i'm a tad rusty atm.

I have a form with a filter in it, whereby the user enters text into a field and upon clicking a button a subsequent subform is filtered to show only those entries that match the search. The following code is tied to a button, "Export to Excel", which uses the OuputTo command to export the data in the subform to Excel:

Code:
Private Sub Command8_Click()
     
    DoCmd.OutputTo acForm, "dbo_EditAdd_subform", acFormatXLS, "C:\Documents and Settings\All Users\Desktop\IT Assets " & Format$(Date, "dd-mm-yy") & ".xls", -1
    
End Sub

I want to know if there is a way to make the filter (below) apply to the subform when it is exported to excel!

Code:
Private Sub Command781_Click()
If Not IsNull(TxtSearch1) Then

Dim stSearchCriteria As String

stSearchCriteria = "[Serial_Number] Like '*" & Me![TxtSearch1] & "*' Or [Type] Like '*" & Me![TxtSearch1] & "*' Or [Model] Like '*" & Me![TxtSearch1] & "*' Or [Class] Like '*" & Me![TxtSearch1] & "*' Or [Username] Like '*" & Me![TxtSearch1] & "*' Or [Department] Like '*" & Me![TxtSearch1] & "*' Or [Location] Like '*" & Me![TxtSearch1] & "*' Or [CPU] Like '*" & Me![TxtSearch1] & "*' Or [OS] Like '*" & Me![TxtSearch1] & "*' Or [RAM] Like '*" & Me![TxtSearch1] & "*' Or [Monitor] Like '*" & Me![TxtSearch1] & "*'"

DoCmd.ApplyFilter , stSearchCriteria
Forms!dbo_EditAdd.dbo_EditAdd_subform.Form.Filter = stSearchCriteria
Me.FilterOn = True
Else

MsgBox "Enter the text to search for", vbOKOnly, "Search Text"

End If

End Sub

formnsubformiq5.jpg


Thanks in advance for any help :)
 

Users who are viewing this thread

Back
Top Bottom