By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,663 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,663 IT Pros & Developers. It's quick & easy.

Multiple parameters for report selected via combo box on a form

P: n/a
Hi All
Here's hoping someone can help me with this.

I have a report based on a query where the criteria for 4 of the fields is
set from an unbound form. I want the user to be able to select any
combination of the combo boxes, some might not be selected etc etc.

ie they may want to select the area and ward to show on the report but not
the case officer or the property type

I am not using parameters but trying to set the where clause via code on the
preview report button on the form. They need to see the report before
printing.

I am a bit of a newbie at this. I have tried to follow various tips and
tutorials in various posts but it will not set any criteria and the report
opens up empty.

I have tried numerous variations of the following including end if after each
combo
If Not IsNull(Me!ChWard) Then

strWhere = "WardName ='" & Me!ChWard & "'"

ElseIf Not IsNull(Me!ChArea) Then
strWhere = strWhere & "AND Area = '" & Me!ChArea & "'"
ElseIf Not IsNull(Me.ChCaseOfficer) Then
strWhere = strWhere & "AND CaseOfficer ='" & Me!ChCaseOfficer & "'"

ElseIf Not IsNull(Me.ChProp) Then
strWhere = strWhere & "AND [Property Type] ='" & Me.ChProp &
"'"

DoCmd.OpenReport RptName, acViewPreview, , strWhere

End If

Where am I going wrong
Any help would be much appreciated.

--
Ceebaby

Trying to be great at Access

Message posted via http://www.accessmonster.com

Sep 23 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
In relation to the above post I have declared

Dim strWhere As String
Dim RptName As String

strWhere = "1=1"
RptName = Me.ReportName

which I should have added in the previous post.
Thanks

Ceebaby wrote:
>Hi All
Here's hoping someone can help me with this.

I have a report based on a query where the criteria for 4 of the fields is
set from an unbound form. I want the user to be able to select any
combination of the combo boxes, some might not be selected etc etc.

ie they may want to select the area and ward to show on the report but not
the case officer or the property type

I am not using parameters but trying to set the where clause via code on the
preview report button on the form. They need to see the report before
printing.

I am a bit of a newbie at this. I have tried to follow various tips and
tutorials in various posts but it will not set any criteria and the report
opens up empty.

I have tried numerous variations of the following including end if after each
combo

If Not IsNull(Me!ChWard) Then

strWhere = "WardName ='" & Me!ChWard & "'"

ElseIf Not IsNull(Me!ChArea) Then
strWhere = strWhere & "AND Area = '" & Me!ChArea & "'"
ElseIf Not IsNull(Me.ChCaseOfficer) Then
strWhere = strWhere & "AND CaseOfficer ='" & Me!ChCaseOfficer & "'"

ElseIf Not IsNull(Me.ChProp) Then
strWhere = strWhere & "AND [Property Type] ='" & Me.ChProp &
"'"

DoCmd.OpenReport RptName, acViewPreview, , strWhere

End If

Where am I going wrong
Any help would be much appreciated.
--
Ceebaby

Trying to be great at Access

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200709/1

Sep 23 '07 #2

P: n/a
it would be a lot easier to add criteria to the query underlying the report.
criteria for WardName would be

Forms!FormName!ChWard or Forms!FormName!ChWard Is Null

the above goes all on the top line in the criteria grid, regardless of line
wrap in this post.
criteria for Area would be

Forms!FormName!ChArea or Forms!FormName!ChArea Is Null

again, all goes on the top line in the criteria grid.
criteria for CaseOfficer would be

Forms!FormName!ChCaseOfficer or Forms!FormName!ChCaseOfficer Is Null

....all on the top line...
and criteria for Property Type would be

Forms!FormName!ChProp or Forms!FormName!ChProp Is Null

....on the top line...
in all instances, replace FormName with the correct name of the form, and
make sure the form stays open while the report is opened (you can make the
form invisible if you don't want it to appear open). since none of the
textbox control values are dates, you should not need to list the criteria
in the Parameters box in query Design view.

hth
"Ceebaby via AccessMonster.com" <u6919@uwewrote in message
news:78a5bf56638ce@uwe...
In relation to the above post I have declared

Dim strWhere As String
Dim RptName As String

strWhere = "1=1"
RptName = Me.ReportName

which I should have added in the previous post.
Thanks

Ceebaby wrote:
Hi All
Here's hoping someone can help me with this.

I have a report based on a query where the criteria for 4 of the fields
is
set from an unbound form. I want the user to be able to select any
combination of the combo boxes, some might not be selected etc etc.

ie they may want to select the area and ward to show on the report but
not
the case officer or the property type

I am not using parameters but trying to set the where clause via code on
the
preview report button on the form. They need to see the report before
printing.

I am a bit of a newbie at this. I have tried to follow various tips and
tutorials in various posts but it will not set any criteria and the
report
opens up empty.

I have tried numerous variations of the following including end if after
each
combo

If Not IsNull(Me!ChWard) Then

strWhere = "WardName ='" & Me!ChWard & "'"

ElseIf Not IsNull(Me!ChArea) Then
strWhere = strWhere & "AND Area = '" & Me!ChArea & "'"
ElseIf Not IsNull(Me.ChCaseOfficer) Then
strWhere = strWhere & "AND CaseOfficer ='" & Me!ChCaseOfficer &
"'"

ElseIf Not IsNull(Me.ChProp) Then
strWhere = strWhere & "AND [Property Type] ='" &
Me.ChProp &
"'"

DoCmd.OpenReport RptName, acViewPreview, , strWhere

End If

Where am I going wrong
Any help would be much appreciated.

--
Ceebaby

Trying to be great at Access

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200709/1

Sep 23 '07 #3

P: n/a
Hi Tina

Thanks for your reply.

I tried this method yesterday, with very limited results. It would work
sometimes then not at all. I tested it using criteria I know appeared in the
underlaying tables. It also seems to change the design grid everytime, its
run. This method only seems to work where there are only 2 parameters.

I tried again just now and the same thing happens. This is why I wanted to
try the vba where clause method instead but I just can't seem to get the
syntax right.
Do you know where I might find the code for 4 parameters using the code
similar to what I posted.

I have looked on various other posts but they seem to stop at 2 combo text
boxes on a form and I have 4. Does using this code make a difference when you
want to open the report in preview mode. The other code seems to be where you
print the report.

Thanks once again for your response though.

Ceebaby
London


tina wrote:
>it would be a lot easier to add criteria to the query underlying the report.
criteria for WardName would be

Forms!FormName!ChWard or Forms!FormName!ChWard Is Null

the above goes all on the top line in the criteria grid, regardless of line
wrap in this post.
criteria for Area would be

Forms!FormName!ChArea or Forms!FormName!ChArea Is Null

again, all goes on the top line in the criteria grid.
criteria for CaseOfficer would be

Forms!FormName!ChCaseOfficer or Forms!FormName!ChCaseOfficer Is Null

...all on the top line...
and criteria for Property Type would be

Forms!FormName!ChProp or Forms!FormName!ChProp Is Null

...on the top line...
in all instances, replace FormName with the correct name of the form, and
make sure the form stays open while the report is opened (you can make the
form invisible if you don't want it to appear open). since none of the
textbox control values are dates, you should not need to list the criteria
in the Parameters box in query Design view.

hth
>In relation to the above post I have declared
[quoted text clipped - 48 lines]
>Where am I going wrong
Any help would be much appreciated.
--
Ceebaby

Trying to be great at Access

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200709/1

Sep 23 '07 #4

P: n/a
there's no reason why the criteria i posted should not work if set up in the
query correctly, and no hard limit of criteria on two fields only. having
said that, the problem with your code is that in an If, Then, Else statement
the code runs the actions for the first matching expression *and then skips
to End If*. so you're never going to get a concatenation of multiple
criteria from your code. instead, try separate If statements, as

If Not IsNull(Me!ChWard) Then
strWhere = "WardName = '" _
& Me!ChWard & "' And"
End If

If Not IsNull(Me!ChArea) Then
strWhere = strWhere & " Area = '" _
& Me!ChArea & "' And"
End If

If Not IsNull(Me!ChCaseOfficer) Then
strWhere = strWhere & " CaseOfficer = '" _
& Me!ChCaseOfficer & "' And"
End If

If Not IsNull(Me!ChProp) Then
strWhere = strWhere & " [Property Type] = '" _
& Me.ChProp & "'"
End If

If Right(strWhere, 4) = " And" Then
strWhere = Trim(Left(strWhere, Len(strWhere)-4))
Else
strWhere = Trim(strWhere)
End If

DoCmd.OpenReport RptName, acViewPreview, , strWhere

hth
"cesima via AccessMonster.com" <u6919@uwewrote in message
news:78a64e016ed7a@uwe...
Hi Tina

Thanks for your reply.

I tried this method yesterday, with very limited results. It would work
sometimes then not at all. I tested it using criteria I know appeared in
the
underlaying tables. It also seems to change the design grid everytime, its
run. This method only seems to work where there are only 2 parameters.

I tried again just now and the same thing happens. This is why I wanted to
try the vba where clause method instead but I just can't seem to get the
syntax right.
Do you know where I might find the code for 4 parameters using the code
similar to what I posted.

I have looked on various other posts but they seem to stop at 2 combo text
boxes on a form and I have 4. Does using this code make a difference when
you
want to open the report in preview mode. The other code seems to be where
you
print the report.

Thanks once again for your response though.

Ceebaby
London


tina wrote:
it would be a lot easier to add criteria to the query underlying the
report.
criteria for WardName would be

Forms!FormName!ChWard or Forms!FormName!ChWard Is Null

the above goes all on the top line in the criteria grid, regardless of
line
wrap in this post.
criteria for Area would be

Forms!FormName!ChArea or Forms!FormName!ChArea Is Null

again, all goes on the top line in the criteria grid.
criteria for CaseOfficer would be

Forms!FormName!ChCaseOfficer or Forms!FormName!ChCaseOfficer Is Null

...all on the top line...
and criteria for Property Type would be

Forms!FormName!ChProp or Forms!FormName!ChProp Is Null

...on the top line...
in all instances, replace FormName with the correct name of the form, and
make sure the form stays open while the report is opened (you can make
the
form invisible if you don't want it to appear open). since none of the
textbox control values are dates, you should not need to list the
criteria
in the Parameters box in query Design view.

hth
In relation to the above post I have declared
[quoted text clipped - 48 lines]
Where am I going wrong
Any help would be much appreciated.

--
Ceebaby

Trying to be great at Access

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200709/1

Sep 23 '07 #5

P: n/a
Hi Tina

Thanks for your time and help on this.
Have tried the code you posted. It is still not working. I dont understand
why it will not work.

The form users select the criteria is open and stays open until it is closed
by the user
The form that the reports name is on is open and the set focus is on the
reportname
the underlying query has all the fields and more in the design grid

The report opens but with no information on it. When I look in design view
the properties filter box has all the criteria selected but it will not
return the values. I have checked the table and used other values and still
nothing comes up.

Is there a particular way I have to structure the query
or could the possible cause be due to 2 forms being open - the user selects
the report which then opens either a date or selection forms.

I cannot think what else I might be missing
Thanks


tina wrote:
>there's no reason why the criteria i posted should not work if set up in the
query correctly, and no hard limit of criteria on two fields only. having
said that, the problem with your code is that in an If, Then, Else statement
the code runs the actions for the first matching expression *and then skips
to End If*. so you're never going to get a concatenation of multiple
criteria from your code. instead, try separate If statements, as

If Not IsNull(Me!ChWard) Then
strWhere = "WardName = '" _
& Me!ChWard & "' And"
End If

If Not IsNull(Me!ChArea) Then
strWhere = strWhere & " Area = '" _
& Me!ChArea & "' And"
End If

If Not IsNull(Me!ChCaseOfficer) Then
strWhere = strWhere & " CaseOfficer = '" _
& Me!ChCaseOfficer & "' And"
End If

If Not IsNull(Me!ChProp) Then
strWhere = strWhere & " [Property Type] = '" _
& Me.ChProp & "'"
End If

If Right(strWhere, 4) = " And" Then
strWhere = Trim(Left(strWhere, Len(strWhere)-4))
Else
strWhere = Trim(strWhere)
End If

DoCmd.OpenReport RptName, acViewPreview, , strWhere

hth
>Hi Tina
[quoted text clipped - 56 lines]
>Where am I going wrong
Any help would be much appreciated.
--
Ceebaby

Trying to be great at Access

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200709/1

Sep 23 '07 #6

P: n/a
Hi Tina

Just to let you know the form and report are working, using both the
parameters on the query referring to the form, and the where clause via vba
you posted above.

The query was based on a many to many table linked to a parent table. I used
this query to create another query to test if it would work and it did.

I will read up on this as I did not think this would cause a problem.

Anyhow its resolved now and thanks once again for your help on this.

Cheers
Ceebaby
London

cesima wrote:
>Hi Tina

Thanks for your time and help on this.
Have tried the code you posted. It is still not working. I dont understand
why it will not work.

The form users select the criteria is open and stays open until it is closed
by the user
The form that the reports name is on is open and the set focus is on the
reportname
the underlying query has all the fields and more in the design grid

The report opens but with no information on it. When I look in design view
the properties filter box has all the criteria selected but it will not
return the values. I have checked the table and used other values and still
nothing comes up.

Is there a particular way I have to structure the query
or could the possible cause be due to 2 forms being open - the user selects
the report which then opens either a date or selection forms.

I cannot think what else I might be missing
Thanks
>>there's no reason why the criteria i posted should not work if set up in the
query correctly, and no hard limit of criteria on two fields only. having
[quoted text clipped - 38 lines]
>>Where am I going wrong
Any help would be much appreciated.
--
Ceebaby

Trying to be great at Access

Message posted via http://www.accessmonster.com

Sep 23 '07 #7

P: n/a
you're welcome :)
"Ceebaby via AccessMonster.com" <u6919@uwewrote in message
news:78a964d2d8190@uwe...
Hi Tina

Just to let you know the form and report are working, using both the
parameters on the query referring to the form, and the where clause via
vba
you posted above.

The query was based on a many to many table linked to a parent table. I
used
this query to create another query to test if it would work and it did.

I will read up on this as I did not think this would cause a problem.

Anyhow its resolved now and thanks once again for your help on this.

Cheers
Ceebaby
London

cesima wrote:
Hi Tina

Thanks for your time and help on this.
Have tried the code you posted. It is still not working. I dont
understand
why it will not work.

The form users select the criteria is open and stays open until it is
closed
by the user
The form that the reports name is on is open and the set focus is on the
reportname
the underlying query has all the fields and more in the design grid

The report opens but with no information on it. When I look in design
view
the properties filter box has all the criteria selected but it will not
return the values. I have checked the table and used other values and
still
nothing comes up.

Is there a particular way I have to structure the query
or could the possible cause be due to 2 forms being open - the user
selects
the report which then opens either a date or selection forms.

I cannot think what else I might be missing
Thanks
>there's no reason why the criteria i posted should not work if set up in
the
>query correctly, and no hard limit of criteria on two fields only.
having
[quoted text clipped - 38 lines]
>Where am I going wrong
Any help would be much appreciated.

--
Ceebaby

Trying to be great at Access

Message posted via http://www.accessmonster.com

Sep 23 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.