I have a splitform that is bound to a query. I'm making this form a search criteria form and am trying to get it to filter results based on a range on a currency field. For example, I have a field (from my query) called "Total Cost". I also have two unbound text boxes on my form header that I'd like to have the capability to do a range between the currency values entered in the text boxes. Like if someone typed in "$1,000" on the "FROM" textbox and "$5,000" on the "TO" texbox, it would filter and show all the records that have a Total Cost in that range in the datasheet part of of the split form. I've been playing around with it alot and can't seem to get it to work. My code is below. The other search criteria I have is working great, it's just the currency range that has been giving me fits. My code is below which is for the OnClick event for a command filter button. Any help would be greatly appreciated!
Code:
Private Sub cmdFilter_Click()
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#"
'Look at each search box, and build up the criteria string from the non-blank ones.
If Not IsNull(Me.txtFilterOrderID) Then
strWhere = strWhere & "([ID] = " & Me.txtFilterOrderID & ") AND "
End If
If Not IsNull(Me.txtFilterContractorName) Then
strWhere = strWhere & "([Name of Contractor] Like ""*" & Me.txtFilterContractorName & "*"") AND "
End If
If Not IsNull(Me.txtFilterCostFrom) Then
strWhere = strWhere & "([Total Cost] = " & Format(Me.txtFilterCostFrom) & ") AND "
End If
If Not IsNull(Me.txtFilterCostTo) Then
strWhere = strWhere & "([Total Cost] = " & Format(Me.txtFilterCostTo ) & ") AND"
End If
'Use the format string to add the # delimiters and get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([Date Requested] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
End If
‘Use "less than the next day" since this field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([Date Requested] < " & Format(Me.txtEndDate + 1, conJetDate) & ")"
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria was entered", vbInformation, "Error"
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub