WineSnob
Not Bright but TENACIOUS
- Local time
- Today, 05:54
- Joined
- Aug 9, 2010
- Messages
- 211
I have a form where I have fields that can be filled in to create a filter. Then the results are returned in a subform. Works Great! Now I need to Append the "filtered" records to a table. I am not sure how to create a query using the filter. I set the recordsource of the subform using the buildfilter but I dont know how to Append the records.
Here is the BuildFilter code:
Here is the subform filter code:
Here is the BuildFilter code:
Code:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varColor As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
'varColor = Null ' Subfilter used for colors
' Check for LIKE First Name
If Me.txtQuoteNumber > "" Then
varWhere = varWhere & "[QuoteNo] LIKE ""*" & Me.txtQuoteNumber & "*"" And "
End If
' Check for LIKE Last Name
If Me.txtAccount > "" Then
varWhere = varWhere & "[Account] LIKE ""*" & Me.txtAccount & "*"" AND "
End If
' Check for CityID
If Me.txtProductType > "" Then
varWhere = varWhere & "[Product Type / Scope] LIKE ""*" & Me.txtProductType & "*"" AND "
End If
' Check for LIKE Address
If Me.cmbAssigned > "" Then
varWhere = varWhere & "[PSR Contact] LIKE ""*" & Me.cmbAssigned & "*"" AND "
End If
' Check for LIKE Zip
'If Me.txtZip > "" Then
' varWhere = varWhere & "[clzip] LIKE """ & Me.txtZip & "*"" AND "
'End If
' Check for min Age
If Me.txtQuoteTotal > "" Then
varWhere = varWhere & "[Quote Total] < " & Me.txtQuoteTotal & " AND "
End If
' Check for max Age
If Me.txtQuoteTotalMore > "" Then
varWhere = varWhere & "[Quote Total] > " & Me.txtQuoteTotalMore & " AND "
End If
' Check for DateModified
If Me.CmbDateModified > "" Then
'varWhere = varWhere & "[Month] Between """ & Me.CmbSTARTMonth.Value & """ And """ & Me.CmbENDMonth.Value & """"
varWhere = varWhere & "[DateModified]> #" & Me.CmbDateModified.Value & "# AND "
'varWhere = varWhere & "[Date] Between #" & Me.CmbSTARTMonth.Value & "# AND #" & Me.CmbENDMonth.Value & "#"
End If
'Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
Debug.Print varWhere
End Function
Here is the subform filter code:
Code:
Me.frmsubClients.Form.RecordSource = "SELECT * FROM MASTER " & BuildFilter