how to solve error 2046 in MS Access 2016?

nzar

New member
Local time
Today, 23:40
Joined
Jul 18, 2020
Messages
2
if the error as below:

Option Compare Database

Private Sub Command77_Click()
'search button
Call Search
End Sub
Sub Search()

Dim strcriteria, task As String

Me.Refresh
If IsNull(Me.OrderDataFrom) Or IsNull(Me.OrderDataTo) Then

MsgBox "Please enter the date range", vbInformation, "Date Range Required"

Me.OrderDataFrom.SetFocus
Else
strcriteria = "([EffectiveDate] >= #" & Me.OrderDataFrom & "# And [EffectiveDate] <= #" & Me.OrderDataTo & "#)"
task = "select * from table1 where(" & strcriteria & ") order by [EffectiveDate]"

DoCmd.ApplyFilter task ←←error in this step

End If
End Sub



please help me to solve this problem
 
Hi. Welcome to AWF!

What is error 2046? Just a guess but maybe try this?

DoCmd.ApplyFilter strcriteria
 
hi Mr
I no understand for you but below my file.
how solve problem?
 

Attachments

I believe that the ApplyFilter method takes the name of a query or named filter, not a sql statement?
I suppose you could use the sql statement as a filter property (as in Me.Filter = task)? Might just as well make the form's recordsource equal to the sql statement though.

nzar: please post code within code tags (</> on toolbar) and provide the error message, not just the number. There are about 3,000 error numbers, and if you want help, you shouldn't be making us look up the number you provide. At least that's my perspective.
 
FYI, I moved your thread to a more appropriate forum. Welcome to AWF!
 
Error 2046 is "The command or action '....' isn't available now" and it tells you (inside the single-quoted string) what command or action wasn't available. We would need to know the exact text of the error to include that quoted material.
 

Users who are viewing this thread

Back
Top Bottom