Solved VBA Clear all data

Rania01

Member
Local time
Today, 02:55
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

I get an error 2580
 
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
 
Because you have a spelling in the query name...you're missing the "y"
 
So just set Filter to "" and FilterOn to False ?
You can still set the controls to "" or Null ? to remove the last entries
 
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

Back
Top Bottom