By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,209 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,209 IT Pros & Developers. It's quick & easy.

Clearing Text/List boxes for new search

100+
P: 114
I'm on the home streach of my project and found that my "Reset for New Search" command button not working as desired. What should happen is that when the button is clicked a Event Procedure is run. That event procedure should clear the text boxes that are used for a search query that loads the results into a list box on that same form.

When clicked, all is cleared in the text boxes, and the list box is cleared but shows column seperator lines in 1st row only . After entering new search data (let's say box 2 of the 3 boxes, and the search data is on the table) the "Search" button is clicked, the list box clears completely and nothing showing.

What I discovered is if I enter something in all 3 text boxes (say x, x, x) and click "Search" nothing happens, and then go back and delete 1st box, enter valid data in 2nd, delete 3rd and click the "Search" button again, the list box get populated like it should of after clearning the 1st search.

I can change any of the text box values and click "Search" not using the clear button, and that works loading new rows in that list box. Just the clear before a new search has problems.

Here is the code for the clear button click:

Private Sub clearButton_Click()
On Error GoTo Err_clearButton_Click
' clear the 3 text boxes, list box so that another search/query can be done
Me.WhatLastName.Value = ""
Me.WhatFirstName.Value = ""
Me.WhatMedRecNo.Value = ""
Me.SelectPrintItems.RowSource = ""
Me.Refresh

Exit_clearButton_Click:
Exit Sub

and here is the code for the search button click:

Private Sub SearchQuery_Click()
On Error GoTo Err_SearchQuery_Click

'Error checking to make sure user entered values for Last Name and First Name.
If Nz(Me.WhatLastName, "") & _
Nz(Me.WhatFirstName, "") & _
Nz(Me.WhatMedRecNo, "") = "" Then
MsgBox ("Please enter a Search value, all 3 may not be blank")
GoTo Exit_SearchQuery_Click
Else
Me.SelectPrintItems.RowSource = "Lukup_Query"
Me.SelectPrintItems.Requery

End If
Exit_SearchQuery_Click:
Exit Sub

The Lukup_Query is just a Select using the What... fields above in a WHERE statement to select for populating the list box.

Should work but I must be overlooking something that is obvious
Jan 1 '07 #1
Share this Question
Share on Google+
12 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Expand|Select|Wrap|Line Numbers
  1. 'Me.SelectPrintItems.RowSource = ""
Comment out this line and see what happens
Jan 1 '07 #2

100+
P: 114
Expand|Select|Wrap|Line Numbers
  1. 'Me.SelectPrintItems.RowSource = ""
Comment out this line and see what happens
When commented out all text & list box get cleared (no col seperators) but functionality still remains the same.
Jan 1 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
When commented out all text & list box get cleared (no col seperators) but functionality still remains the same.
Try doing the same with the text boxes just leaving Me.Refresh
Jan 1 '07 #4

100+
P: 114
Try doing the same with the text boxes just leaving Me.Refresh
When all are commented out the Clear does nothing, but the Search works every time with any changes to any of the text boxes.
Jan 1 '07 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
When all are commented out the Clear does nothing, but the Search works every time with any changes to any of the text boxes.
Expand|Select|Wrap|Line Numbers
  1.      Me.WhatLastName = Null
  2.     Me.WhatFirstName = Null
  3.     Me.WhatMedRecNo = Null
Try this instead for the text boxes.

BTW are the textboxes bound to controls. If not the refresh should have worked.

Mary
Jan 1 '07 #6

100+
P: 114
Expand|Select|Wrap|Line Numbers
  1.      Me.WhatLastName = Null
  2.     Me.WhatFirstName = Null
  3.     Me.WhatMedRecNo = Null
Try this instead for the text boxes.

BTW are the textboxes bound to controls. If not the refresh should have worked.

Mary
that seems to work ok, just when the form open 1st time and when the Clear button is clicked the entire table is listed in the list box (29230 records). In design mode the text boxes and list box all show Unbound
Jan 1 '07 #7

MMcCarthy
Expert Mod 10K+
P: 14,534
that seems to work ok, just when the form open 1st time and when the Clear button is clicked the entire table is listed in the list box (29230 records). In design mode the text boxes and list box all show Unbound
Try setting the listbox RowSource to "" again while leaving the textboxes set to null.
Jan 1 '07 #8

100+
P: 114
Try setting the listbox RowSource to "" again while leaving the textboxes set to null.
That seems to work as to clearing text boxes, and the list box, except the column dividers for the 1st row show, but can live with that.

The search works OK now and the only thing is that the list box loads the entire table when the form is first opened.
Jan 1 '07 #9

MMcCarthy
Expert Mod 10K+
P: 14,534
That seems to work as to clearing text boxes, and the list box, except the column dividers for the 1st row show, but can live with that.

The search works OK now and the only thing is that the list box loads the entire table when the form is first opened.
Call the clear button event in the On load event of the form

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.    clearButton_Click
  4.  
  5. End Sub
Mary
Jan 2 '07 #10

100+
P: 114
Call the clear button event in the On load event of the form

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.    clearButton_Click
  4.  
  5. End Sub
Mary
Thanks Mary that worked. I think the list box is loading but being cleared after. The reason I say this is the time it takes for the form to open.
Jan 2 '07 #11

MMcCarthy
Expert Mod 10K+
P: 14,534
Thanks Mary that worked. I think the list box is loading but being cleared after. The reason I say this is the time it takes for the form to open.
The other option is to put it in the on close event of the form.
Jan 2 '07 #12

100+
P: 114
Thanks to all of you that have helped me even on a holiday. It works the way I wanted it to function.
Jan 2 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.