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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Text Boxes After Running Query

Status
Not open for further replies.
Jul 10, 2008
32
US


There's a screenshot of one of the forms for my database. I'm having a problem with the "Clear Text" function. I want the user to be able to click that button and clear all 6 of the unbound text boxes, either before or after they execute a search. As of right now, it will clear them if you click it after you hit Search ONLY if your search returned records. If you run the query and no records are returned, the Clear function acts funky. When you press the button, it will not clear them until you actually click in and out of each one of the text boxes. Also, it works if you click the button before you hit Search (like if you're filling out the fields and make a mistake and decide to start over), unless of course the last query you ran returned no results, then you'll have the problem I described above.

Here's my code:
Code:
Option Compare Database

Private Sub ClearButton_Click()

Me.EnterClientNumber = Null
Me.EnterClientName = Null
Me.EnterProjectNumber = Null
Me.EnterProjectDescrip = Null
Me.EnterProjectManager = Null
Me.EnterDiscID = Null

EnterClientNumber.SetFocus

End Sub

Private Sub CloseButton_Click()
On Error GoTo Err_CloseButton_Click


    DoCmd.Close

Exit_CloseButton_Click:
    Exit Sub

Err_CloseButton_Click:
    MsgBox Err.Description
    Resume Exit_CloseButton_Click
    
End Sub

Private Sub SearchButton_Click()

DoCmd.OpenForm "SearchForm", , , , , acDialog

End Sub

Private Sub SearchButton2_Click()

        'Filter data based on search criteria
        Form_ViewDataForm.RecordSource = "SearchQuery2"
        Form_ViewDataForm.Caption = "Search Results"
        
        MsgBox "Results have been filtered."
End Sub

Private Sub ShowAllButton_Click()

Dim LSQL  As String
    
    'Display all customers
    LSQL = "SELECT Client.[Client ID], Project.[Project ID], Disc.[Disc ID], Client.[Client Description], Project.[Project Description], Project.[Project Manager] FROM (Client INNER JOIN Project ON Client.[Client ID]=Project.[Client ID]) INNER JOIN (Disc INNER JOIN [Project On Disc] ON Disc.[Disc ID]=[Project On Disc].[Disc ID]) ON Project.[Project ID]=[Project On Disc].[Project ID] ORDER BY Client.[Client ID], Project.[Project ID], Disc.[Disc ID]"
    
    Form_ViewDataForm.RecordSource = LSQL
    Form_ViewDataForm.Caption = "View all records"
    
    MsgBox ("All records are now displayed.")
    
End Sub
Private Sub GenerateReportButton_Click()
On Error GoTo Err_GenerateReportButton_Click

    Dim stDocName As String

    stDocName = "rptSearchResults"
    DoCmd.OpenReport stDocName, acPreview

Exit_GenerateReportButton_Click:
    Exit Sub

Err_GenerateReportButton_Click:
    MsgBox Err.Description
    Resume Exit_GenerateReportButton_Click
    
End Sub

Any suggestions?
 
Hmmm...

Have you tried:

Me.EnterClientNumber = ""
Me.EnterProjectNumber = ""
Me.EnterProjectDescrip = ""
Me.EnterProjectManager = ""
Me.EnterDiscID = ""

Instead ?

You say they are unbound, and I don't see where any of your code references them....strange....


Tyrone Lumley
SoCalAccessPro
 
I tried both of these suggestions and neither of them worked.

Yes, they are unbound, they are simply used to input text to run a query with. I don't understand why it's happening either. But since it only happens when there are no results returned from a query, I'm almost certain it's something wrong with my Search button, like I need another line of code to handle the situation of having no results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top