filtering a report using a combo box

L

Linda

I am trying to filter a report by allowing the user to
choose a location from a combo box list in a dialog box.
I have used the 'Microsoft Access help' and have created
my dialog box and created and attached my macros.
However, I am not using date parameters for my filtering
so, I'm not sure how to set the criteria. Also, can I
even use a combo box to select the filtering criteria?

Thanks
 
A

Albert D. Kallal

Her is what I do.

First, create a nice form that is going to prompt the user. You can then use
the wizard to build the combo box. (note that the form, and the combo box is
un-bound. By un-bound we simply mean that the form will not save data, nor
will the combo box).

You then place a button on the form with the following code to launch the
form:

dim strWhere as string

if isnull(cboLocation) = false then

strWhere = "Location = '" & cboLocaton & "'"

endif

docmd.OpenReport "YourReport",acViewPreview,,strWhere

Now, remember, remove all parameters from the query that the report is based
on, since we are NOT USING parameters, but only using the where clause.
While the above is a bit of code, I do find it much cleaner then trying to
use funny expressions in the query.

If you want to see how well the above idea works, take a look at the
following screen shots of ms-access reports. All of the screen shots use the
above code idea, and thus all the queries don't have to have any parameters.
You just build the report, and then build a nice report screen, and use the
"where" clause of the open report to restrict the records to the users
choice.

Check out :

http://www.attcanada.net/~kallal.msn/ridesrpt/ridesrpt.html

The other advantage of the code soltion is that the user can leave the combo
"blank", and all values will be returned.
 
A

Annelie

Thank you, so simple if you know how, I finally can filter my reports.
Now, I am asking for more. How about multiple criteria, Like 2 text boxes
with StartDate and EndDate?
Annelie
 
P

Pedro

Hi everyone,
I've tried also this solution but it's not working. It
shows me the report with no values. Here is my code :

Private Sub Command2_Click()

Dim strWhere As String

If IsNull(cboNome) = False Then

strWhere = "Nome = '" & cboNome & "'"

End If

DoCmd.OpenReport "Apagar", acViewPreview, , strWhere

End Sub

It appears to be simple but i'm not an expert so that's
why i'm having dificulties.
Can anybody help me please?
Tks in advance
Pedro
 
A

Annelie

Does your combobox work as far as selecting your data?
I found that when I could not get a code to work on a previous try, that my
name field was not name properly - take a look at that.
 

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