I have a main form (Main Archive Form) with a subform (frmarchivesubform). The subform's record source is a query called "Dynamic_Query". On the main form I have a combo box and two text boxes that specify search criteria and a command button that executes the search.
The command button has the following code in it:
Private Sub Command48_Click()
Dim db As DAO.Database
Dim QD As DAO.QueryDef
Dim SQL As String
Dim vWhere As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete "Dynamic_Query"
On Error GoTo 0
vWhere = Null
If IsNull(Me.StartDispatchDate) And IsNull(Me.EndDispatchDate) Then
vWhere = vWhere & (" and [Drop Point(s)]='" + Me.Drop_Point_s_ + "'")
End If
If IsNull(Me.StartDispatchDate) = False And IsNull(Me.EndDispatchDate) = True Then
vWhere = vWhere & (" and [Drop Point(s)]='" + Me.Drop_Point_s_ + "'")
vWhere = vWhere & (" and [Dispatch Date]=#" & Me.StartDispatchDate & "#")
End If
If IsNull(Me.StartDispatchDate) = False And IsNull(Me.EndDispatchDate) = False Then
vWhere = vWhere & (" and [Drop Point(s)]='" + Me.Drop_Point_s_ + "'")
vWhere = vWhere & (" and [Dispatch Date] between #" & Me.StartDispatchDate & "# AND #" & Me.EndDispatchDate & "#")
End If
SQL = "SELECT * FROM [Forecast] " & (" WHERE " + Mid(vWhere, 5))
Set QD = db.CreateQueryDef("Dynamic_Query", SQL)
Me.frmArchivesubform.Form.Requery
End Sub
Everything displays correctly when the Main form first loads, but when I put new criteria in and click the command button, nothing happens. But, if I were to close down the Main form and get back in, then my new criteria would be there. This tells me that my Query is being updated properly.
Could someone give me some insight as to why my subform display is not being updated?
Thanks!
Steve
The command button has the following code in it:
Private Sub Command48_Click()
Dim db As DAO.Database
Dim QD As DAO.QueryDef
Dim SQL As String
Dim vWhere As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete "Dynamic_Query"
On Error GoTo 0
vWhere = Null
If IsNull(Me.StartDispatchDate) And IsNull(Me.EndDispatchDate) Then
vWhere = vWhere & (" and [Drop Point(s)]='" + Me.Drop_Point_s_ + "'")
End If
If IsNull(Me.StartDispatchDate) = False And IsNull(Me.EndDispatchDate) = True Then
vWhere = vWhere & (" and [Drop Point(s)]='" + Me.Drop_Point_s_ + "'")
vWhere = vWhere & (" and [Dispatch Date]=#" & Me.StartDispatchDate & "#")
End If
If IsNull(Me.StartDispatchDate) = False And IsNull(Me.EndDispatchDate) = False Then
vWhere = vWhere & (" and [Drop Point(s)]='" + Me.Drop_Point_s_ + "'")
vWhere = vWhere & (" and [Dispatch Date] between #" & Me.StartDispatchDate & "# AND #" & Me.EndDispatchDate & "#")
End If
SQL = "SELECT * FROM [Forecast] " & (" WHERE " + Mid(vWhere, 5))
Set QD = db.CreateQueryDef("Dynamic_Query", SQL)
Me.frmArchivesubform.Form.Requery
End Sub
Everything displays correctly when the Main form first loads, but when I put new criteria in and click the command button, nothing happens. But, if I were to close down the Main form and get back in, then my new criteria would be there. This tells me that my Query is being updated properly.
Could someone give me some insight as to why my subform display is not being updated?
Thanks!
Steve