473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple parameters for report selected via combo box on a form

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
7 3978
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
2
by: Jen F. | last post by:
I have inherited a medical database in which there are multiple values stored in a single field (ie. "Current Conditions" field might contain 1-20 different conditions, separated by comma (ie....
2
by: mumbaimacro | last post by:
hi i have two combo boxes in a form with values from a table. i need a report to be opened by a button from the form ,The Report should show the values selected in the combo boxes in the form...
6
by: jim | last post by:
Is anyone able to provide me with a link to useful documentation or just outright explain to me how to set query parameters dynamically? I'm really new to Access and databases in general but I...
1
by: Intrepid_Yellow | last post by:
Hi, I have the following code that runs my report generator. The user selects a table from a combo box, then whatever fields they want from a list box. (This part all works and the report runs...
3
hyperpau
by: hyperpau | last post by:
Hi there guys! I have a Form where there are three comboboxes. This comboboxes are used as references for the parameter of 3 fields in a query. when I hit a command button in my form, it opens...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
1
by: zufie | last post by:
I have 4 combo boxes on a report for the fields, City, County, IBCCP Agency Name, and Other Agency Name. The row source for City is: SELECT DISTINCTROW ., . FROM ; This allows the values...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.