how to solve error 2046 in MS Access 2016? (1 Viewer)

nzar

New member
Local time
Today, 16:09
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:09
Joined
Oct 29, 2018
Messages
21,357
Hi. Welcome to AWF!

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

DoCmd.ApplyFilter strcriteria
 

nzar

New member
Local time
Today, 16:09
Joined
Jul 18, 2020
Messages
2
hi Mr
I no understand for you but below my file.
how solve problem?
 

Attachments

  • Login - Copy.accdb
    4.6 MB · Views: 557

Micron

AWF VIP
Local time
Today, 09:09
Joined
Oct 20, 2018
Messages
3,476
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.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:09
Joined
Aug 30, 2003
Messages
36,118
FYI, I moved your thread to a more appropriate forum. Welcome to AWF!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:09
Joined
Feb 28, 2001
Messages
26,996
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

Top Bottom