YES. I can be done. But I don't think you would want to code it.Saving a Filter as a Query in VB Via a button, Can it be done?
Private Sub Command28_Click()
Dim strFilter As String
If Len([Location] & "") = 0 Then
Else
strFilter = [Location]
End If
If Len([User] & "") = 0 Then
Else
strFilter = "[User] = " & strfilter
End If
If Len([Manufacturer] & "") = 0 Then
Else
strFilter = "[Manufacturer] = " & strfilter
End If
If Len([Model] & "") = 0 Then
Else
strFilter = "[Model] = " & strfilter
End If
If Len([Model Number] & "") = 0 Then
Else
strFilter = "[Model Number] = " & strfilter
End If
If Len([Anti Virus] & "") = 0 Then
Else
strFilter = "[Anti Virus] = " & strfilter
End If
If Len(strFilter) > 0 Then
DoCmd.ApplyFilter strFilter
Requery
DoCmd.Save acQuery, "IR"
Else
FilterOn = False
End If
DoCmd.OpenForm "Advanced Inventory Search"
Private Sub Command28_Click()
Dim strFilter As String
[COLOR="SeaGreen"][COLOR="Cyan"][COLOR="Indigo"]strFilter = ""[/COLOR][/COLOR][/COLOR] [color=red]<---- You may need this line to give the string variable an initial value[/color]
If Len([Location] & "") = 0 Then
Else
strFilter = [Location]
End If
If Len([User] & "") = 0 Then
Else
strFilter = "[User] = " & strfilter
End If
If Len([Manufacturer] & "") = 0 Then
Else [color=red]<--- This is not needed in an IF statement if you're only checking one condition[/color]
strFilter = "[Manufacturer] = " & strfilter
End If
If Len([Model] & "") = 0 Then
Else [color=red]<--- This is not needed in an IF statement if you're only checking one condition[/color]
strFilter = "[Model] = " & strfilter
End If
If Len([Model Number] & "") = 0 Then
Else [color=red]<--- This is not needed in an IF statement if you're only checking one condition[/color]
strFilter = "[Model Number] = " & strfilter
End If
If Len([Anti Virus] & "") = 0 Then
Else
strFilter = "[Anti Virus] = " & strfilter
End If
If Len(strFilter) > 0 Then
DoCmd.ApplyFilter strFilter
Requery
DoCmd.Save acQuery, "IR"
Else
[COLOR="Red"]Do you have an object to go with this filter command? --->[/COLOR]FilterOn = False
End If
DoCmd.OpenForm "Advanced Inventory Search"
If Len([field]) & "" > 0
If Isnull([field]
If [Location] = "" Then
Else
strFilter = [Location]
End If
If [Manufacturer] = "" Then
Else
strFilter = "[Manufacturer] = " & strfilter
End If
If IsNull([Location]) Or [Location] = "" Then
Else
strFilter = [Location]
End If
If IsNull([Location]) Or [Manufacturer] = "" Then
Else
strFilter = "[Manufacturer] = " & strfilter
End If
Private Sub Command28_Click()
Dim strFilter As String
If Len([Location] & "") [COLOR="Red"]<---This will [U]always[/U] be greater than 0[/COLOR] = 0 Then
Else
strFilter = [Location]
End If
If Len([User] & "") [COLOR="Red"]<---This will [U]always[/U] be greater than 0[/COLOR] = 0 Then
Else
strFilter = "[User] = " & strfilter
End If
If Len([Manufacturer] & "") [COLOR="Red"]<---This will [U]always[/U] be greater than 0[/COLOR] = 0 Then
Else
strFilter = "[Manufacturer] = " & strfilter
End If
If Len([Model] & "") [COLOR="Red"]<---This will [U]always[/U] be greater than 0[/COLOR] = 0 Then
Else
strFilter = "[Model] = " & strfilter
End If
If Len([Model Number] & "") [COLOR="Red"]<---This will [U]always[/U] be greater than 0[/COLOR] = 0 Then
Else
strFilter = "[Model Number] = " & strfilter
End If
If Len([Anti Virus] & "") [COLOR="Red"]<---This will [U]always[/U] be greater than 0[/COLOR] = 0 Then
Else
strFilter = "[Anti Virus] = " & strfilter
End If
DoCmd.ApplyFilter strFilter
Requery
DoCmd.Save acQuery, "IR"
DoCmd.OpenForm "Advanced Inventory Search"
DoCmd.ApplyFilter strFilter
Requery
DoCmd.Save acQuery, "IR"
You are opening the "Advance Inventory Search" form after this. Is that the form you want to filter? Is that the form with the query as its source? Instead of trying to filter the form's source, which does not have the ability to hold code, why can't you just source the form with the source table of the query?? That's the best way to do it anyway...Ahhhh Ic Ic so go with the IsNull, now (assuming that the filter works) saving the Filter as a Query at the end of the filter i put:
Code:DoCmd.ApplyFilter strFilter Requery DoCmd.Save acQuery, "IR"
that do command probably not right i was just winging it there lol. dose anyone know how to save it as a filter i need to use this at several different points in the database. or maybe there is a better way of going about it i don't think it can be done with macros or syntax, still very new to the programming part of access.
Private Sub Command28_Click()
Dim strFilter As String
If IsNull([Location]) Or [Location] = "" Then
Else
strFilter = [Location]
End If
If IsNull([Manufacturer]) Or [Manufacturer] = "" Then
Else
strFilter = "[Manufacturer] = " & strfilter
End If
If IsNull([User]) Or [User] = "" Then
Else
strFilter = "[User] = " & strfilter
End If
If IsNull([Model]) Or [Model] = "" Then
Else
strFilter = "[Model] = " & strfilter
End If
If IsNull([Model Number]) Or [Model Number] = "" Then
Else
strFilter = "[Model Number] = " & strfilter
End If
If IsNull([Anti Virus]) Or [Anti Virus] = "" Then
Else
strFilter = "[Anti Virus] = " & strfilter
End If
DoCmd.ApplyFilter strFilter
Requery
DoCmd.Save acQuery, "IR"
DoCmd.OpenForm "Advanced Inventory Search"
If IsNull([Location]) Or [Location] = "" Then
Else
strFilter = [Location]
End If
If IsNull([Manufacturer]) Or [Manufacturer] = "" Then
Else
strFilter = "[Manufacturer] = " & strfilter
End If
If IsNull([User]) Or [User] = "" Then
Else
strFilter = "[User] = " & strfilter
End If
If IsNull([Model]) Or [Model] = "" Then
Else
strFilter = "[Model] = " & strfilter
End If
If IsNull([Model Number]) Or [Model Number] = "" Then
Else
strFilter = "[Model Number] = " & strfilter
End If
If IsNull([Anti-Virus]) Or [Anti-Virus] = "" Then
Else
strFilter = "[Anti-Virus] = " & strfilter
End If
If IsNull([Anti-Virus]) Or [Anti-Virus] = "" Then
Else
strFilter = "[Anti-Virus] = " & strfilter
End If