Solved VBA Clear all data (1 Viewer)

Rania01

Member
Local time
Today, 21:02
Joined
Oct 9, 2021
Messages
59
Please help how to resolved this issue

I made Command button to clear the value on search by date and showing all data again
I get an error 2580

I use below VBA

Code:
Private Sub CDMClear_Click()
Dim task As String

Me.DateFrom = Null
Me.DateTo = ""

task = "select * from qrySearch order by [ProdDate]"
Me.RecordSource = task

End Sub
 

Attachments

  • Search Data.accdb
    532 KB · Views: 70

Gasman

Enthusiastic Amateur
Local time
Today, 20:02
Joined
Sep 21, 2011
Messages
14,315
And what is your issue?
 

Rania01

Member
Local time
Today, 21:02
Joined
Oct 9, 2021
Messages
59
I get an error 2580
 

Rania01

Member
Local time
Today, 21:02
Joined
Oct 9, 2021
Messages
59
Code:
Private Sub cmdSearch_Click()
Call Search
End Sub



Private Sub Search()
Dim strCriteria, task As String

    Me.Refresh
    If IsNull(Me.DateFrom) Or IsNull(Me.DateTo) Then
        MsgBox "Please Enter Date Range", vbInformation, "Date Range Required"
        Me.DateFrom.SetFocus
    Else
        strCriteria = "[ProdDate] BETWEEN " & Format(Me.DateFrom, strcJetDate) & " AND " & Format(Me.DateTo, strcJetDate)
        Debug.Print strCriteria
        Me.Filter = strCriteria
        Me.FilterOn = True


End If
End Sub
 

bastanu

AWF VIP
Local time
Today, 12:02
Joined
Apr 13, 2010
Messages
1,402
Because you have a spelling in the query name...you're missing the "y"
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:02
Joined
Sep 21, 2011
Messages
14,315
So just set Filter to "" and FilterOn to False ?
You can still set the controls to "" or Null ? to remove the last entries
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:02
Joined
Sep 21, 2011
Messages
14,315
Code:
Private Sub cmdSearch_Click()
Call Search
End Sub



Private Sub Search()
Dim strCriteria, task As String

    Me.Refresh
    If IsNull(Me.DateFrom) Or IsNull(Me.DateTo) Then
        MsgBox "Please Enter Date Range", vbInformation, "Date Range Required"
        Me.DateFrom.SetFocus
    Else
        strCriteria = "[ProdDate] BETWEEN " & Format(Me.DateFrom, strcJetDate) & " AND " & Format(Me.DateTo, strcJetDate)
        Debug.Print strCriteria
        Me.Filter = strCriteria
        Me.FilterOn = True


End If
End Sub
BTW, you have not Dimmed your variables correctly. :(

strCriteria will be a Variant and task the only string variable.
You MUST define each a type, else they become Variant.
 

Users who are viewing this thread

Top Bottom