Filter records in form selected in listbox

G

Guest

I have problems filtering records shown in a form based on what is selected
in the listbox.

It's a little bit complicated but it has to be this way. Form #1 contains
two comboboxes with month and year. Clicking on this form will open Form #2
that contains a listbox that has two columns. When clicking on the listbox I
want to open Form #3 that should filter the records to only show the ones
with the selected month, year, listcolumn1 and listcolumn2. I am able to
filter by month and year from the combobox by having a macro openform where
[Month]=[Forms]![frmMain]![comboMonth] And
[Year]=[Forms]![frmMain]![comboYear].

However, my problem is filtering out the records to only show from the two
columns in the listbox. Form #3 has two textboxes that will be needed to be
compared to the listbox and show only the selected records. I tried this code
in the macro event where, which I get an error message "undefined function
[listbox].[column]:
[Expr1] = [Forms]![frmName]![listbox]. Column(0) AND
[Expr2] = [Forms]![frmName]![listbox]. Column(1)

What should I do to make it work.
 
G

Guest

First, It does not have to be this way. There are better ways. This could
all be done on one form.

Second, what you are trying to do cannot be done with Macros. It will take
some fairly advanced VBA to accomplish filtering based on what is selected in
the list boxes.

This statement is confusing:

Form #3 has two textboxes that will be needed to be compared to the listbox
and show only the selected records

How will they be compared? How does this affect the filtering of the records?

Also, is your list box a multi select list box?

If you can give a description of what it is you are trying to accomplish, we
can perhaps come up with a workable solution for you.
 
G

Guest

I decided to have a form with subform, which does exactly what I need. The
reason I wanted to have it on one form is because I read that you cannot
export subforms to excel. What I want is explained more in details under
"cannot get code to work". As long as I can get the form w/subform to be
saved in Excel I'm happy!!

Klatuu said:
First, It does not have to be this way. There are better ways. This could
all be done on one form.

Second, what you are trying to do cannot be done with Macros. It will take
some fairly advanced VBA to accomplish filtering based on what is selected in
the list boxes.

This statement is confusing:

Form #3 has two textboxes that will be needed to be compared to the listbox
and show only the selected records

How will they be compared? How does this affect the filtering of the records?

Also, is your list box a multi select list box?

If you can give a description of what it is you are trying to accomplish, we
can perhaps come up with a workable solution for you.

Elleve said:
I have problems filtering records shown in a form based on what is selected
in the listbox.

It's a little bit complicated but it has to be this way. Form #1 contains
two comboboxes with month and year. Clicking on this form will open Form #2
that contains a listbox that has two columns. When clicking on the listbox I
want to open Form #3 that should filter the records to only show the ones
with the selected month, year, listcolumn1 and listcolumn2. I am able to
filter by month and year from the combobox by having a macro openform where
[Month]=[Forms]![frmMain]![comboMonth] And
[Year]=[Forms]![frmMain]![comboYear].

However, my problem is filtering out the records to only show from the two
columns in the listbox. Form #3 has two textboxes that will be needed to be
compared to the listbox and show only the selected records. I tried this code
in the macro event where, which I get an error message "undefined function
[listbox].[column]:
[Expr1] = [Forms]![frmName]![listbox]. Column(0) AND
[Expr2] = [Forms]![frmName]![listbox]. Column(1)

What should I do to make it work.
 

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