Okay, so I'm working on a database application with a search form that covers a ton of fields. And everything worked fine, until I tried to set it to pull records that have a value between two numbers. These numbers are years, but the fields aren't in a date format, just a normal integer format. The field in the table is called ActiveDate, and the search form has numActiveFrom and numActiveTo. I can't seem to get the code to run it, and I can't figure out what's wrong with the damned thing. The text fields all work fine, but not the number fields specified above. Below is the bit of code that relates to this field. I'm also including the bit just before and the bit just after it for context. Any help would be very much appreciated. Please let me know if you need any other details.
Code:
' Do Public Knowledge next
If Not IsNothing(Me.txtPublic) Then
' .. add to the predicate
varWhere = (varWhere + " AND ") & "[PublicKnowledge] LIKE '*" & Me.txtPublic & "*'"
End If
' Check Active From first
If Not IsNothing(Me.numActiveFrom) Then
' .. build the predicate
varWhere = (varWhere + " AND ") & "[ActiveDate] >= #" & CInt(Me.numActiveFrom) & "#"
End If
' Then, do Active To
If Not IsNothing(Me.numActiveTo) Then
' .. add to the predicate
varWhere = (varWhere + " AND ") & "[ActiveDate] <= #" & CInt(Me.numActiveTo) & "#"
End If
' Check to see that we built a filter
If IsNothing(varWhere) Then
MsgBox "You must enter at least one search criteria.", vbInformation, gstrAppTitle
Exit Sub
End If
' Open a recordset to see if any rows returned with this filter
Set rst = db.OpenRecordset("SELECT * FROM [tblCharactersMain] WHERE " & varWhere)
' See if found none
If rst.RecordCount = 0 Then
MsgBox "No characters meet your criteria.", vbInformation, gstrAppTitle
' Clean up recordset
rst.Close
Set rst = Nothing
Exit Sub
End If
Comment