Listbox shows no records but its value set to previous search's value

  • Thread starter Thread starter Chuck
  • Start date Start date
C

Chuck

Hello,

I have a listbox control in a form. The listbox will returns a list of
records based on a query. Lets say that the first search returns 5 records.
If I double-click record 2 in the listbox, it will open another form an go
to that record. Now I do another search but this time the list box returns
zero records. I can still click the control and it will still open the
other form to the previous searches value. I added msgbox me!MyList.value
to the control's OnDoubleClick event and it does in fact output the previous
search's value.

Why is that?

Thanks
 
Chuck said:
Hello,

I have a listbox control in a form. The listbox will returns a list of
records based on a query. Lets say that the first search returns 5 records.
If I double-click record 2 in the listbox, it will open another form an go
to that record. Now I do another search but this time the list box returns
zero records. I can still click the control and it will still open the
other form to the previous searches value. I added msgbox me!MyList.value
to the control's OnDoubleClick event and it does in fact output the previous
search's value.

Why is that?

Because the value is still in memeory as the item selected. It was, the last
item selected, after all. What you need to do is to clear the selected value
in the double-click event right after the form open code, but before the
exit line. Properly formed code has an exit label (sub routine) and error
handling before the End Sub. If your code is like that, you can put it
there.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Hi Arvin!

I have the exact same problem.

Can you please tell me the code I need to put in? What
would be the syntax for clearing it?

Thanks!
--Toan
 
What I typically do, is to set a textbox = to the value(s) selected in a
list box. The line of code being:

Me.txtWhatever = Me.lstWhatever

I use the txtWhatever reference in my code or query. Later, when I've run
the code or query and need to clear the text box, I can just use:

Me.txtWhatever = Null

The advantage to this method is the cases when the list box is multi-select,
I can concatenate the values in a text box, and simply use an IN clause to
pass the values to the where clause.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top