473,568 Members | 2,795 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 3996
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
4295
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
6549
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...
2
2025
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 -->...
6
1699
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...
1
2485
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,...
3
2691
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...
6
9395
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....
1
1545
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...
12
4022
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
7693
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...
0
7604
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...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6275
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...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
932
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...

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.