Shah
Shah

Reputation: 11

Syntax error 3075 in calling from another procedure

I m trying to filter records between two dates on a split form through Search button which calls the following code

Sub search()

Dim strCriteria ,taSk As String 

Me.Refresh
If IsNull(Me.txtDiaryDatefrom) Or IsNull(Me.txtDiaryDateTo) 
Then
    MsgBox "Please Enter Date Range", vbInformation, "Date Range Required"
    Me.txtDiaryDatefrom.SetFocus 
Else
    strCriteria = "([DiaryDate]>= # " & Me.txtDiaryDatefrom & " # And [DiaryDate] <= #" & Me.txtDiaryDateTo & " # )"
    taSk = "SELECT * from tblDiary where ( " & strCriteria & ")"
    DoCmd.ApplyFilter , taSk 
End If 

End Sub

Upon execution it gives the Run-time error 3075 reading

syntax error in query expression 'Select * from tblDiary .....

Could anyone figure out what is needed to fix it ??

Upvotes: 1

Views: 33

Answers (1)

user6432984
user6432984

Reputation:

You need to remove the spaces between the hashes.

"([DiaryDate]>= #" & Me.txtDiaryDatefrom & "# And [DiaryDate] <= #" & Me.txtDiaryDateTo & "# )"

I would change the query so that the end [DiaryDate] < Date + 1. This will ensure that records that have date/time values will not accidentally get filtered out.

"([DiaryDate]>= #" & DateValue(Me.txtDiaryDatefrom) & "# And [DiaryDate] < #" & DateValue(Me.txtDiaryDateTo) + 1 & "# )"

Upvotes: 1

Related Questions