My issue is that I have a form with two unbound text boxes (txt_DateBegin, txt_DateEnd) that I’m trying to use to pass date parameters to an “On Click” event on a button on the same form (frm_DateRanges). I want users to key in date ranges, then the event will pass those dates to a query where clause. When I try this, I get and “Object Required” error. Addionally, when I try to run a query with the value from the form, I get a blank result: [SELECT [Forms]![frm_DateRanges]![txt_DateBegin] AS X;]
When I change the format in properties from Short Date to make it a true text value, the query works, it passes the text value when I run the select statement above.
My VBA for the “On Click” event is below:
Private Sub cmd_Terms_Click()
On Error GoTo Err_cmd_Terms_Click
Dim stDocName As String
Dim stBegin As Date
Dim stEnd As Date
Dim stCriteria As String
If Forms!frm_DateRanges.txt_DateBegin.Value Is Null Or Forms!frm_DateRanges.txt_DateEnd.Value Is Null Then
MsgBox ("Please select a Begin and End Date for your request")
stBegin = Forms!frm_DateRanges.txt_DateBegin.Value
stEnd = Forms!frm_DateRanges.txt_DateEnd.Value
stCriteria = "[Termination_Date] >= #" & stBegin & "# and [Termination_Date] <= #" & stEnd & "#"
stDocName = "qry_FacGenRpt_ALL"
DoCmd.OpenQuery stDocName, acNormal, acReadOnly
DoCmd.ApplyFilter , stCriteria
Any help getting these dates to pass appropriately is much appreciated.