M
MaryAnn
Thanks for reading. Hope you can help.
How do I handle date ranges (code) in a dynamic query?
Here's what I have so far... Date of Hire needs to be a
range rather than a static value. In the table the date
was inputed as MM/DD/YY. Thanks for any assistance.
Option Compare Database
Option Explicit
Private Sub cmdRunQuery_Click()
Dim MyDatabase As Database
Dim MyQueryDef As QueryDef
Dim rs As Recordset
Dim where As Variant
Set MyDatabase = CurrentDb()
If ObjectExists("Queries", "qryDynamic_QBF") = True
Then
MyDatabase.QueryDefs.Delete "qryDynamic_QBF"
MyDatabase.QueryDefs.Refresh
End If
where = Null
where = where & " AND [Clock Number]= '" + Me!
[txtClock] + "'"
where = where & " AND [Last Name]= '" + Me!
[Text15] + "'"
where = where & " AND [Date of Hire]= '" + Me!
[Text4] + "'"
where = where & " AND [Location]= '" + Me![Text12]
+ "'"
where = where & " AND [Title]= '" + Me![Combo23]
+ "'"
where = where & " AND [Union]= '" + Me![Combo27]
+ "'"
Set MyQueryDef = MyDatabase.CreateQueryDef
("qryDynamic_QBF", _
"Select * from EADDataForPhotos " & (" where " + Mid
(where, 6) & ";"))
Set Recordset = MyDatabase.OpenRecordset("Select *
from EADDataForPhotos " & (" where " + Mid(where, 6)
& ";"))
If Recordset.RecordCount = 0 Then
MsgBox "No Records were found"
Else
DoCmd.OpenQuery "qryDynamic_QBF"
DoCmd.OpenForm "Search Results"
Forms![Search Results].Requery
DoCmd.Close acQuery, "qryDynamic_QBF"
End If
End Sub
How do I handle date ranges (code) in a dynamic query?
Here's what I have so far... Date of Hire needs to be a
range rather than a static value. In the table the date
was inputed as MM/DD/YY. Thanks for any assistance.
Option Compare Database
Option Explicit
Private Sub cmdRunQuery_Click()
Dim MyDatabase As Database
Dim MyQueryDef As QueryDef
Dim rs As Recordset
Dim where As Variant
Set MyDatabase = CurrentDb()
If ObjectExists("Queries", "qryDynamic_QBF") = True
Then
MyDatabase.QueryDefs.Delete "qryDynamic_QBF"
MyDatabase.QueryDefs.Refresh
End If
where = Null
where = where & " AND [Clock Number]= '" + Me!
[txtClock] + "'"
where = where & " AND [Last Name]= '" + Me!
[Text15] + "'"
where = where & " AND [Date of Hire]= '" + Me!
[Text4] + "'"
where = where & " AND [Location]= '" + Me![Text12]
+ "'"
where = where & " AND [Title]= '" + Me![Combo23]
+ "'"
where = where & " AND [Union]= '" + Me![Combo27]
+ "'"
Set MyQueryDef = MyDatabase.CreateQueryDef
("qryDynamic_QBF", _
"Select * from EADDataForPhotos " & (" where " + Mid
(where, 6) & ";"))
Set Recordset = MyDatabase.OpenRecordset("Select *
from EADDataForPhotos " & (" where " + Mid(where, 6)
& ";"))
If Recordset.RecordCount = 0 Then
MsgBox "No Records were found"
Else
DoCmd.OpenQuery "qryDynamic_QBF"
DoCmd.OpenForm "Search Results"
Forms![Search Results].Requery
DoCmd.Close acQuery, "qryDynamic_QBF"
End If
End Sub