View Full Version : Filter SubForm by changing query criteria


darnnnel
12-12-2007, 08:06 AM
Hello everyone. i have a fom and subform (they are not linked).The subform has a date field named StartDate. i have a button on the form that when clicked will change the recordset of the subform to show StartDate of today. When i hit the command button, the subform becomes blank.Its driving me crazy.Here is my code:

Private Sub cmdToday_Click()

Dim sSQL As String
Dim Today
Today = Format(Now(), "mm/dd/yyyy")

sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate = " & Today
Forms!ViewCases![ViewCasesSubform].Form.RecordSource = sSQL

End Sub

Uncle Gizmo
12-12-2007, 12:02 PM
One possible problem is the use of "today" I believe today is a reserved word and this may be causing issues in your program.

The other thing to watch out for is if your field "StartDate" contains time information as well as date information then it may not return records properly.