Selecting a value in a list box to be used in a query

S

Supynuts

I would like my users to choose a value from a list box that gets entered
into the field of a query. For example, a record is pulled by a 4 digit ID,
yet to see the progress of sales for this ID, many months need to be scrolled
through are compared to the current month (which is held static on the form).
I would rather them select from a box the month they want to compare and
have the fields be populated in the forms bound controls. What is the best
way to do this? I tried having the criteria of the query look to the control
on the form, but it doesn't allow the form to open without requesting the
parameter value first...I want the user to be able to see the form and choose
from the list box instead.

Thanks for the assistnace in advance
 
C

Carl Rapson

Supynuts said:
I would like my users to choose a value from a list box that gets entered
into the field of a query. For example, a record is pulled by a 4 digit
ID,
yet to see the progress of sales for this ID, many months need to be
scrolled
through are compared to the current month (which is held static on the
form).
I would rather them select from a box the month they want to compare and
have the fields be populated in the forms bound controls. What is the
best
way to do this? I tried having the criteria of the query look to the
control
on the form, but it doesn't allow the form to open without requesting the
parameter value first...I want the user to be able to see the form and
choose
from the list box instead.

Thanks for the assistnace in advance

Remove the criteria from the query (I assume this is the query that the form
is based on). In the AfterUpdate event of the listbox, change the form's
Record Source property to incorporate the month selection:

Me.RecordSource = "SELECT * FROM [query] WHERE [month]=" & listbox

At any point, if you want to restore the form's Record Source to the full
(unfiltered) query, just set it again:

Me.RecordSource = "SELECT * FROM [query]"

Carl Rapson
 

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