Annoying problem...Running a Query off of a Listbox

N

NoviceNana

I've been working on this for a few days and it's annoying the crap
out of me. I have a form that has a listbox bound to a query and 5 or
so fields. The listbox is bound to a query and lists the names of all
the clients in the system. When you click on a name in the listbox
the fields on the form (Name, address, birthdate, etc) all autofill
using a macro in the AfterUpdate on the listbox.

This all works perfectly.

Now I want to put a button on the page that will run and export a
parameter query with the parameter being the ClientID number. The
Client ID number is one of the fields that autopopulates on the for,
but I can't for the life of me get the query to run filtered to the ID
number that is selected from the listbox.

Can anyone help me?
p.s. on anothe form I have the name list and I have other queries in
different listboxes on the form. It would be GREAT if those queries
would also requery when a name is clicked in the listbox
 
G

Guest

Hi,

You can try something like this for your query:

SELECT ClientID, Name, address, birthdate, etc
FROM myTableName
Where ClientID = [Forms]![myFormName]![myListBoxName]

If that doesn't work try this:
SELECT ClientID, Name, address, birthdate, etc
FROM myTableName
Where ClientID = Eval("[Forms]![myFormName]![myListBoxName]")

To requery your listboxes or comboboxes just add VBA like this to the
AfterUpdate Event of your ListBox or to the Click Event of your button:

Me.myListBoxName.Requery
Me.myNextListBoxName.Requery
Me.myComboBoxName.Requery

Also, add that code to your Form's Current Event

That's it.

Hunter57
 

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