Hello,
I have a BeginDate field and an EndDate field on my form that filters via a command button the data on the form to just the dates within the range entered by the user. I just have a form, frmNetworkPerformance (no subform), based on a table, tblNetworkPerformance.
The code in the On Click for the command button works below, but I need to add a line that if either of the dates do not exists, then a msgbox will appear saying, "BeginDate (or EndDate, whichever is applicable) Not Found" (I'm not working on this quite yet, I will have a variable called strDate, I think):
I need help with the 2 date fields as criteria on the WHERE statement. This is what I have tried but I'm having trouble with having 2 criteria for the WHERE and am getting lost with the apostrophes for the BeginDate and EndDate. I need the (space) and underscore in the code before the OR b/c the line of code is too long. (I haven't gotten to the part where I put strDate = to something; I'll work on that later.
With just 1 criteria after the WHERE, I get "Run-time error '3061'. Too few parameters. Expected 1." I know it has to do with quotes but I've not worked with Recordset and Dates before.
With both criteria as I have posted below, the first line of code with the IF and SQL statement are red and the macro recorder opens up but it is empty.
I would appreciate any help!
I have a BeginDate field and an EndDate field on my form that filters via a command button the data on the form to just the dates within the range entered by the user. I just have a form, frmNetworkPerformance (no subform), based on a table, tblNetworkPerformance.
The code in the On Click for the command button works below, but I need to add a line that if either of the dates do not exists, then a msgbox will appear saying, "BeginDate (or EndDate, whichever is applicable) Not Found" (I'm not working on this quite yet, I will have a variable called strDate, I think):
Code:
Private Sub cmdNtwkFilterByDate_Click()
With Me.Form
.Filter = "[DateNetwork] BETWEEN #" & Me.BeginDate & "# AND #" & Me.EndDate & "#"
.FilterOn = True
End With
End If
End Sub
I need help with the 2 date fields as criteria on the WHERE statement. This is what I have tried but I'm having trouble with having 2 criteria for the WHERE and am getting lost with the apostrophes for the BeginDate and EndDate. I need the (space) and underscore in the code before the OR b/c the line of code is too long. (I haven't gotten to the part where I put strDate = to something; I'll work on that later.
With just 1 criteria after the WHERE, I get "Run-time error '3061'. Too few parameters. Expected 1." I know it has to do with quotes but I've not worked with Recordset and Dates before.
With both criteria as I have posted below, the first line of code with the IF and SQL statement are red and the macro recorder opens up but it is empty.
I would appreciate any help!
Code:
Private Sub cmdNtwkFilterByDate_Click()
Dim strDate as Date
If CurrentDb.OpenRecordset("SELECT DateNetwork FROM tblNetworkPerformance WHERE BeginDate<>" & "#" & Forms!frmNetworkPerformance!BeginDate & "#" _
OR EndDate<>" & "#" & Forms!frmNetworkPerformance!EndDate & "#"& ";", dbOpenSnapshot) Then
MsgBox (strDate &" Not Found")
Else
With Me.Form
.Filter = "[DateNetwork] BETWEEN #" & Me.BeginDate & "# AND #" & Me.EndDate & "#"
.FilterOn = True
End With
End If
End Sub