csababenyi

New Member
Joined
Nov 17, 2020
Messages
15
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
  2. Web
Hi All.

I am trying to create a simple date search function but Access always complaining about the DoCmd.ApplyFilter task.

See below. Any insight would be greatly appriciated.

1618906819016.png


VBA Code:
Option Compare Database

Private Sub Command22_Click()
' Search button
Call Search
End Sub
Sub Search()
Dim strCriteria, task As String

Me.Refresh
If IsNull(Me.OrderDateFrom) Or IsNull(Me.OrderDateTo) Then
    MsgBox "Kérem adjon meg dátum sort", vbInformation, "Dátum sor Szükséges"
    Me.OrderDateFrom.SetFocus
Else
    strCriteria = "([DATUM] >= #" & Me.OrderDateFrom & "& And [DATUM] <= #" & Me.OrderDateTo & "#)"
        task = "select * from tEFI2021 where (" & strCriteria & ") order by [DATUM]"
    DoCmd.ApplyFilter task
   
End If

End Sub

Private Sub Command23_Click()
Dim task As String

    Me.OrderDateFrom = Null
    Me.OrderDateTo = ""
        task = "select * from tEFI2021 where (" & strCriteria & ") order by [DATUM]"
        DoCmd.ApplyFilter task
   
    
End Sub

Search button Syntax Error (Missing Operator):
1618906290897.png


Clear button Sytnax Error (Missing Operator):
1618914569642.png


Got stuck, must be something simple I am overlooking. Thank you.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Found 1 typo and corrected it, but now when using Search this is the new error message.

Before:
VBA Code:
strCriteria = "([DATUM] >= #" & Me.OrderDateFrom & "& And [DATUM] <= #" & Me.OrderDateTo & "#)"

After:
VBA Code:
strCriteria = "([DATUM] >= #" & Me.OrderDateFrom & "# And [DATUM] <= #" & Me.OrderDateTo & "#)"

1618916073929.png


DoCmd.ApplyFilter task is still highlighted with yellow.

the Clear button has no change same error as before.
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,915
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top