I am ready to tear my hair out. Something simple seems to be such a pain. I have done alot of research with different ideas but I just keep coming up with problems.
I have a simple query based on a form for the user to put in the start and end dates they want to retreive totals for. I want to error check if an empty recordset is returned.
Not sure what I am doing wrong. This is erroring out on the parameters. I had tried me.OpenRecordset.reccount = 0 but that did not work. When I hovered over it in VB code it displayed my TxtEndDate as the openrecordset.
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Set dbs = CurrentDb
'Get the parameter query
Set qfd = dbs.QueryDefs("Query Total by Month")
' set query parameters
qdf.Parameters("TxtStartDate") = Me.TxtStartDate ' ("TxtStartDate") = Parameter in Query and me.TxtStartDate is the parameter entered on Form
qdf.Parameters("TxtEndDate") = Me.TxtEndDate ' ("TxtEndDate") = Parameter in Query and Me.TxtEndDate is the parameter entered on Form
' Open a Recordset based on the parameter query
Set rst = qdf.OpenRecordset()
Me.Requery
' Check to see if query returns an empty record set and reset the form
If rst.RecordCount = 0 Then
MsgBox "No records Found for Parameters", vbExclamation
Me.TxtStartDate = "01/01/2010" ' I have a blank record to reset all totals on form to blank and makes the form empty with 1 record in the query to start
Me.TxtEndDate = "01/01/2010"
Me.Requery
Me.TxtStartDate = ""
Me.TxtEndDate = ""
Me.TxtMonth = ""
Me.TxtYear = ""
Exit Sub
End If