473,698 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!ChWar d) Then

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

ElseIf Not IsNull(Me!ChAre a) Then
strWhere = strWhere & "AND Area = '" & Me!ChArea & "'"
ElseIf Not IsNull(Me.ChCas eOfficer) Then
strWhere = strWhere & "AND CaseOfficer ='" & Me!ChCaseOffice r & "'"

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

DoCmd.OpenRepor t 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 4009
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!ChWar d) Then

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

ElseIf Not IsNull(Me!ChAre a) Then
strWhere = strWhere & "AND Area = '" & Me!ChArea & "'"
ElseIf Not IsNull(Me.ChCas eOfficer) Then
strWhere = strWhere & "AND CaseOfficer ='" & Me!ChCaseOffice r & "'"

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

DoCmd.OpenRepor t 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.c om
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.c om" <u6919@uwewro te in message
news:78a5bf5663 8ce@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!ChWar d) Then

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

ElseIf Not IsNull(Me!ChAre a) Then
strWhere = strWhere & "AND Area = '" & Me!ChArea & "'"
ElseIf Not IsNull(Me.ChCas eOfficer) Then
strWhere = strWhere & "AND CaseOfficer ='" & Me!ChCaseOffice r &
"'"

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

DoCmd.OpenRepor t 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.c om
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.c om
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!ChWar d) Then
strWhere = "WardName = '" _
& Me!ChWard & "' And"
End If

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

If Not IsNull(Me!ChCas eOfficer) Then
strWhere = strWhere & " CaseOfficer = '" _
& Me!ChCaseOffice r & "' And"
End If

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

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

DoCmd.OpenRepor t RptName, acViewPreview, , strWhere

hth
"cesima via AccessMonster.c om" <u6919@uwewro te in message
news:78a64e016e d7a@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.c om
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!ChWar d) Then
strWhere = "WardName = '" _
& Me!ChWard & "' And"
End If

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

If Not IsNull(Me!ChCas eOfficer) Then
strWhere = strWhere & " CaseOfficer = '" _
& Me!ChCaseOffice r & "' And"
End If

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

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

DoCmd.OpenRepor t 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.c om
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.c om" <u6919@uwewro te in message
news:78a964d2d8 190@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
4313
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
6573
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. "Heart Disease,Hyper Tyroid,Cancer" etc. I would like to search via combo box for any one or more than one value in this field, ie-what patients have Heart Disease or Cancer by selecting these disorders off the combo box list. Any help would be...
2
2037
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 and also i am going to show some other values from tables in the report with that. example: form view: month: jan --> selected from combobox year : 2006 --> selected from combobox
6
1705
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 suspect that there is a way to insert criteria into a query besides opening it up and typing "and" and "or" on the criteria row of each column. I have a query that shows thousands of records (students in different classes taking different tests)...
1
2496
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 fine). There is then a combo box they can select a field from (eg CompanyID etc) and then the list box below that contains the values (eg Microsoft, Novell etc). These are all multi-select list boxes. Now I can get the code to work if the user...
3
2698
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 a query with the parameters selected from the form. Let's say I have three fields in my query. ,, and On the design view of the query, I put these criterias on different lines so that it would be using the OR: =!!
6
9420
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 report" button located on my form to print all of the list box values (that have been updated via selection from combo boxes) from the form to the report. I've tried using a macro with the code: Macro Name: cmdGenerateReport : On Click Action:...
1
1556
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 selected on the combo box on my main form to show up on my report. The row source for County is: SELECT DISTINCTROW ., . FROM ; This also returns the values selected on the combo box on my main form
12
4034
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 not several, to report using this code i found - Private Sub cmdPreview_Click()
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9012
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2319
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1992
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.