So I took the code from the link and tried to apply it just to the date field.
the "srchDate" box is in the main form and [TransDate] is the control in the subform.
When I click the button, nothing happens. No error, no nothing, using the code below. I'm sure it has something to do with the subform reference, but I don't know how to correct. I'm also tried Forms.sbfrmEditRecords.[TransDate], but also didn't work.
'Thanks.
Code:
Private Sub cmdsrchDate_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\#" 'The format expected for dates in a JET query string.
'Date field example. Use the format string to add the # delimiters and get the right international format.
If Not IsNull(Me.srchDate) Then
strWhere = strWhere & "([Forms]![sbfrmEditRecords]![TransDate] = " & Format(Me.srchDate, conJetDate) & ")" And ""
End If
'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub