Hello all,
I am trying to refer to two unbound controls ("begin date" and "end date" on a report that holds a short date value, and use those values to filter a query with a date field.
I am a VBA novice but I learn a little bit every day.
I am using 2010.
I found this code here to save the dates in the unbound controls on the report:
I found this code via Allen Browne, which I believe would filter the query, but I am getting error of "type mismatch"...
I would like the field qryAgencyInvolvTypeQuery.[Start Date] to be less than the ending date, greater than the beginning date, and allow either of the date fields to be null.
:banghead:
I am trying to refer to two unbound controls ("begin date" and "end date" on a report that holds a short date value, and use those values to filter a query with a date field.
I am a VBA novice but I learn a little bit every day.
I am using 2010.
I found this code here to save the dates in the unbound controls on the report:
Code:
Private Sub txtAgnBegin_KeyUp(KeyCode As Integer, Shift As Integer)
SaveTyping = Me.txtAgnBegin.Text
End Sub
Private Sub txtAgnBegin_LostFocus()
Me.txtAgnBegin = SaveTyping
End Sub
Private Sub txtAgnEnd_KeyUp(KeyCode As Integer, Shift As Integer)
SaveTyping = Me.txtAgnEnd.Text
End Sub
Private Sub txtAgnEnd_LostFocus()
Me.txtAgnEnd = SaveTyping
End Sub
I found this code via Allen Browne, which I believe would filter the query, but I am getting error of "type mismatch"...
Code:
Dim strDateFilter As String
Dim strDateField As String
Const strcJetDate = "\#mm\/dd\/yyyy\#" 'Do NOT change it to match your local settings.
strDateField = "qryAgencyInvolvTypeQuery.[Start Date]"
If IsDate(Me.txtAgnBegin) Then
strDateFilter = "(" & strDateField & " >= " & Format(Me.txtAgnBegin, strcJetDate) & ")"
End If
If IsDate(Me.txtAgnEnd) Then
If strDateFilter <> vbNullString Then
strDateFilter = strDateFilter & " AND "
End If
strDateFilter = strDateFilter & "(" & strDateField & " < " & Format(Me.txtAgnEnd + 1, strcJetDate) & ")"
End If
I would like the field qryAgencyInvolvTypeQuery.[Start Date] to be less than the ending date, greater than the beginning date, and allow either of the date fields to be null.
:banghead: