Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset button won't work if no returned records

Status
Not open for further replies.

GelC

Technical User
Oct 3, 2006
93
US
I have a button to reset my form after filtering.
If there is at least a record in result, then reset form...it works perfectly. However, if the result returns no record, it seems doing the job in the back but the text I enter in the form is staying there still.
How come it doesn't work properly on my form?

Code:
Private Sub cmdReset_Click()
    Me.txtKeywords = Null
    Me.cboRptType = Null
    Me.cboArea = Null

    Me.txtRecordCount = Null
    Me.ogSort = 1
    
    Me.Filter = "(False)"
    Me.FilterOn = True
    Me.OrderByOn = False
    
    Me.txtKeywords.SetFocus
End sub

This is the code to search
Code:
Private Sub cmdSearch_Click()
        Me.Filter = Left$(strWhere, lngLen)
        Me.FilterOn = True
        Me.OrderBy = strOrderBy
        Me.OrderByOn = True

        
        If (Me.Recordset.RecordCount > 0) Then
            Me.FormFooter.Visible = True
        Else
            'if no records found
            MsgBox "No record found based on your search criteria." 
            Me.cmdReset.SetFocus     
        End If

Exit_cmdSearch_Click:
    Exit Sub

Err_cmdSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdSearch_Click
End Sub
 
How about trying this line of code to clear it out:

Form.Requery

Also, if those text boxes are accepting string values, then you may be goign about it wrong. Perhaps it shoudl be:
Code:
Private Sub cmdReset_Click()
    Me.txtKeywords = vbNullString
    Me.cboRptType = vbNullString
    Me.cboArea = vbNullString

    Me.txtRecordCount = vbNullString
    Me.ogSort = 1
    
    Me.Filter = "(False)"
    Me.FilterOn = True
    Me.OrderByOn = False
    
    Me.txtKeywords.SetFocus
End sub

If neither of those work in and of themselves, try adding the Requery portion just past the Me.OrderByOn = False

--

"If to err is human, then I must be some kind of human!" -Me
 
Code:
    Me.Filter = "(False)"
    Me.FilterOn = True
I'm not familiar with the first line just above. I'd use
[tt] Me.Filter = "" [/tt]

If you're trying to remove the filter, set .FilterOn to False (and it probably doesn't matter whether you change .Filter).

[purple]If we knew what it was we were doing, it would not be called
research [blue]database development[/blue], would it? [tab]-- Albert Einstein[/purple]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top