Query results to listbox

D

Dennis D.

Hello:

On a form:
Trying to display results of a query in a listbox.

Textbox | Button | Listbox

The textbox takes the criteria for a query.
The button executes the query.
The Listbox displays the results of the query.

So I've been unsuccessfully poking around with this for awhile.

How do I get the button to update the listbox with the query results?
 
D

Duane Hookom

How does the "textbox takes the criteria for a query"?
You may just need to requery the list box.
 
J

John Vinson

Hello:

On a form:
Trying to display results of a query in a listbox.

Textbox | Button | Listbox

The textbox takes the criteria for a query.
The button executes the query.
The Listbox displays the results of the query.

So I've been unsuccessfully poking around with this for awhile.

How do I get the button to update the listbox with the query results?

You don't need the button, and you don't need to (and should not)
"run" the query. Simply use the name of the Query as the RowSource
property of the listbox, and requery the listbox in the AfterUpdate
event of the textbox.

John W. Vinson[MVP]
 
D

Dennis D.

Duane Hookom said:
How does the "textbox takes the criteria for a query"?
The user types in the criteria into the textbox.
The textbox is referenced as the criteria of fields in the query.
as [forms].[formname].[controlname]

You may just need to requery the list box.
 
D

Dennis D.

John Vinson said:
You don't need the button, and you don't need to (and should not)
"run" the query. Simply use the name of the Query as the RowSource
property of the listbox, and requery the listbox in the AfterUpdate
event of the textbox.
I used a command button for a (sendkeys) tab so the user does not need to
know about using a tab key to requery. Works pretty good. Thanks.
 
D

Duane Hookom

John Vinson provided the appropriate answer. Since you didn't reply with a
follow-up question, I assume you got his solution working.

--
Duane Hookom
MS Access MVP

Dennis D. said:
Duane Hookom said:
How does the "textbox takes the criteria for a query"?
The user types in the criteria into the textbox.
The textbox is referenced as the criteria of fields in the query.
as [forms].[formname].[controlname]
 
J

John Vinson

I used a command button for a (sendkeys) tab so the user does not need to
know about using a tab key to requery. Works pretty good. Thanks.

SendKeys is VERY buggy and unreliable, and is never required... If the
user really needs the reassurance of clicking a button, just have it
requery the listbox. Sending a tab key won't do any good anyhow since
if the user clicks the button, the textbox no longer has the focus!

John W. Vinson[MVP]
 
D

Dennis D.

John Vinson said:
SendKeys is VERY buggy and unreliable, and is never required... If the
user really needs the reassurance of clicking a button, just have it
requery the listbox. Sending a tab key won't do any good anyhow since
if the user clicks the button, the textbox no longer has the focus!

John W. Vinson[MVP]

Your solution works well. I used the button to requery the listbox. BTW, I
read up on SendKeys and was reminded that it opens a comm channel that can
be picked off. Thanks John.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top