473,385 Members | 1,343 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,385 software developers and data experts.

Report based on check box and list box...

I have a form (Change Card List by Status) with a check box
(cboNOT) and a list box (lstStatus). There is an Open Report button
that opens a report (Report - Change Card List) which uses a query
(SQL -Change Card List).

What I want to do is have the form open the report where a filter
is set to use the values from the check box AND the value selected
from the list box to generate the report.

What I can't figure out is how to use the check box's value in this
filter. If the check box is not checked the the filter would only be
based on the list box selection, but if the check box is selected, the
filter will select all records where NOT list box selection =
table.field.

So basically it seems like the filter needs to be changed based on
the check box. I think maybe a text string in code in a click event on
the Open Report button could set this filter string, but from that
point I don't know how to get the form to open the report (it in not
currently done by code) and how to set the filter of the report to the
form string.

Thanks for your help!
Jan 11 '08 #1
5 6692
On Jan 11, 11:08*am, Andrew Meador <amead...@hotmail.comwrote:
* *I have a form (Change Card List by Status) with a check box
(cboNOT) and a list box (lstStatus). There is an Open Report button
that opens a report (Report - Change Card List) which uses a query
(SQL -Change Card List).

* *What I want to do is have the form open the report where a filter
is set to use the values from the check box AND the value selected
from the list box to generate the report.

* *What I can't figure out is how to use the check box's value in this
filter. If the check box is not checked the the filter would only be
based on the list box selection, but if the check box is selected, the
filter will select all records where NOT list box selection =
table.field.

* *So basically it seems like the filter needs to be changed based on
the check box. I think maybe a text string in code in a click event on
the Open Report button could set this filter string, but from that
point I don't know how to get the form to open the report (it in not
currently done by code) and how to set the filter of the report to the
form string.

* *Thanks for your help!
Dynamically build your query when the user clicks the button to
generate the report. I do the exact same thing in one of my databases
where the report form has 8 list boxes, several check boxes, and a
hand full of text boxes to enter various date ranges. Pass the sql
you build to the report via code and you have what you want.
Jan 11 '08 #2
On Jan 11, 12:38*pm, frogste...@yahoo.com wrote:
On Jan 11, 11:08*am, Andrew Meador <amead...@hotmail.comwrote:


* *I have a form (Change Card List by Status) with a check box
(cboNOT) and a list box (lstStatus). There is an Open Report button
that opens a report (Report - Change Card List) which uses a query
(SQL -Change Card List).
* *What I want to do is have the form open the report where a filter
is set to use the values from the check box AND the value selected
from the list box to generate the report.
* *What I can't figure out is how to use the check box's value in this
filter. If the check box is not checked the the filter would only be
based on the list box selection, but if the check box is selected, the
filter will select all records where NOT list box selection =
table.field.
* *So basically it seems like the filter needs to be changed based on
the check box. I think maybe a text string in code in a click event on
the Open Report button could set this filter string, but from that
point I don't know how to get the form to open the report (it in not
currently done by code) and how to set the filter of the report to the
form string.
* *Thanks for your help!

Dynamically build your query when the user clicks the button to
generate the report. *I do the exact same thing in one of my databases
where the report form has 8 list boxes, several check boxes, and a
hand full of text boxes to enter various date ranges. *Pass the sql
you build to the report via code and you have what you want.- Hide quoted text -

- Show quoted text -
Well, my thinking was close. I need to build the filter in code and
then pass it to the report. I assume I could do it in a similar way as
you are talking about as far as passing the whole query to the report.
The problem is I don't know how to do this. If you can give a sample
or refer me to directions on how to do this that would be excellent!

Thanks!
Jan 11 '08 #3
On Jan 11, 12:47*pm, Andrew Meador <amead...@hotmail.comwrote:
On Jan 11, 12:38*pm, frogste...@yahoo.com wrote:


On Jan 11, 11:08*am, Andrew Meador <amead...@hotmail.comwrote:
* *I have a form (Change Card List by Status) with a check box
(cboNOT) and a list box (lstStatus). There is an Open Report button
that opens a report (Report - Change Card List) which uses a query
(SQL -Change Card List).
* *What I want to do is have the form open the report where a filter
is set to use the values from the check box AND the value selected
from the list box to generate the report.
* *What I can't figure out is how to use the check box's value in this
filter. If the check box is not checked the the filter would only be
based on the list box selection, but if the check box is selected, the
filter will select all records where NOT list box selection =
table.field.
* *So basically it seems like the filter needs to be changed basedon
the check box. I think maybe a text string in code in a click event on
the Open Report button could set this filter string, but from that
point I don't know how to get the form to open the report (it in not
currently done by code) and how to set the filter of the report to the
form string.
* *Thanks for your help!
Dynamically build your query when the user clicks the button to
generate the report. *I do the exact same thing in one of my databases
where the report form has 8 list boxes, several check boxes, and a
hand full of text boxes to enter various date ranges. *Pass the sql
you build to the report via code and you have what you want.- Hide quoted text -
- Show quoted text -

* *Well, my thinking was close. I need to build the filter in code and
then pass it to the report. I assume I could do it in a similar way as
you are talking about as far as passing the whole query to the report.
The problem is I don't know how to do this. If you can give a sample
or refer me to directions on how to do this that would be excellent!

Thanks!- Hide quoted text -

- Show quoted text -
many ways to accomplish this. One is to declare a global variable as
a string. In the module where user clicks the button to build the SQL
assign the dynamically built SQL to the global string. Then in the
code for the form set the source to that variable.
Jan 11 '08 #4
Andrew Meador wrote:
I have a form (Change Card List by Status) with a check box
(cboNOT) and a list box (lstStatus). There is an Open Report button
that opens a report (Report - Change Card List) which uses a query
(SQL -Change Card List).

What I want to do is have the form open the report where a filter
is set to use the values from the check box AND the value selected
from the list box to generate the report.

What I can't figure out is how to use the check box's value in this
filter. If the check box is not checked the the filter would only be
based on the list box selection, but if the check box is selected, the
filter will select all records where NOT list box selection =
table.field.

So basically it seems like the filter needs to be changed based on
the check box. I think maybe a text string in code in a click event on
the Open Report button could set this filter string, but from that
point I don't know how to get the form to open the report (it in not
currently done by code) and how to set the filter of the report to the
form string.

Thanks for your help!
This might get you started in a direction that'll work for you.

Private Sub CommandReport_Click()
Dim var As Variant
Dim strF As String 'holds report filter

If Me.ListBoxName.ItemsSelected.Count 0 Then

'some items in listbox are selected. Change ListBoxName
'to your name. Assumes the key is the first column in the
'list box. If you have 4 columns, the first is 0, last is 3.
For Each var In Me.ListBoxName.ItemsSelected
strF = strF & Me.ListBoxName.Column(0, var) & ", "
Next

'remove the ", " and surround keys/values in ()
strF = "(" & Left(strF, Len(strHold) - 2) & ")"

'now see if it is "IN" list or "Exclude" list.
strF = "ID " & IIf(Me.CheckBox, "Not ", "") & _
"IN " & strF & " And "

'result so far is "ID (not) IN (1,2,3) And "

'let's pretend there's a text box code. Use single quotes
If Me.Code "" Then
strF = strF & "Code = '" & Me.Code & "' And "
End If

'lets pretend the dollar amt must be value. No quotes
If Me.DollarAmt 0 Then
strF = strF & "DollarAmt >= " & Me.DollarAmt & " And "
End If

'and we have a date range. Use # around dates
If Not IsNull(Me.FromDate) Then
strF = strF & "DateFld >= #" & Me.FromDate & "# And "
End If
If Not IsNull(Me.ToDate) Then
strF = strF & "DateFld <= #" & Me.ToDate & "# And "
End If

'now remove the trailing "And"
strF = Left(strF, Len(strF) - 5)

'now call the report with filter
DoCmd.OpenReport "TestReport", , , strF

Else
MsgBox "Please select some items from listbox."
End If

Exit Sub
Too Long
http://www.youtube.com/watch?v=hb8uv4lGnno

Jan 12 '08 #5
On Jan 11, 9:37*pm, Salad <o...@vinegar.comwrote:
Andrew Meador wrote:
* *I have a form (Change Card List by Status) with a check box
(cboNOT) and a list box (lstStatus). There is an Open Report button
that opens a report (Report - Change Card List) which uses a query
(SQL -Change Card List).
* *What I want to do is have the form open the report where a filter
is set to use the values from the check box AND the value selected
from the list box to generate the report.
* *What I can't figure out is how to use the check box's value in this
filter. If the check box is not checked the the filter would only be
based on the list box selection, but if the check box is selected, the
filter will select all records where NOT list box selection =
table.field.
* *So basically it seems like the filter needs to be changed based on
the check box. I think maybe a text string in code in a click event on
the Open Report button could set this filter string, but from that
point I don't know how to get the form to open the report (it in not
currently done by code) and how to set the filter of the report to the
form string.
* *Thanks for your help!

This might get you started in a direction that'll work for you.

Private Sub CommandReport_Click()
* * *Dim var As Variant
* * *Dim strF As String *'holds report filter

* * *If Me.ListBoxName.ItemsSelected.Count 0 Then

* * * * *'some items in listbox are selected. *Change ListBoxName
* * * * *'to your name. *Assumes the key is the first column in the
* * * * *'list box. *If you have 4 columns, the first is 0, last is 3.
* * * * *For Each var In Me.ListBoxName.ItemsSelected
* * * * * * *strF = strF & Me.ListBoxName.Column(0, var) &", "
* * * * *Next

* * * * *'remove the ", " and surround keys/values in ()
* * * * *strF = "(" & Left(strF, Len(strHold) - 2) & ")"

* * * * *'now see if it is "IN" list or "Exclude" list.
* * * * *strF = "ID " & IIf(Me.CheckBox, "Not ", "") & _
* * * * * * *"IN " & strF & " And "

* * * * 'result so far is "ID (not) IN (1,2,3) And "

* * * * *'let's pretend there's a text box code. *Use single quotes
* * * * *If Me.Code "" Then
* * * * * * *strF = strF & "Code = '" & Me.Code & "' And"
* * * * *End If

* * * * *'lets pretend the dollar amt must be value. *No quotes
* * * * *If Me.DollarAmt 0 Then
* * * * * * *strF = strF & "DollarAmt >= " & Me.DollarAmt & " And "
* * * * *End If

* * * * *'and we have a date range. *Use # around dates
* * * * *If Not IsNull(Me.FromDate) Then
* * * * * * *strF = strF & "DateFld >= #" & Me.FromDate & "# And "
* * * * *End If
* * * * *If Not IsNull(Me.ToDate) Then
* * * * * * *strF = strF & "DateFld <= #" & Me.ToDate & "# And "
* * * * *End If

* * * * *'now remove the trailing "And"
* * * * *strF = Left(strF, Len(strF) - 5)

* * * * 'now call the report with filter
* * * * *DoCmd.OpenReport "TestReport", , , strF

* * *Else
* * * * *MsgBox "Please select some items from listbox."
* * *End If

Exit Sub

Too Longhttp://www.youtube.com/watch?v=hb8uv4lGnno- Hide quoted text -

- Show quoted text -
Wow! Thanks! That was really helpfull, I'm still fresh to actually
getting hands on coding done as well as working in Access and this was
very enlightening. Not too long for me, gave me a few new ideas!
I appreciate your time and thoroughness!

Andrew
Jan 14 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
4
by: Sami | last post by:
I hope someone will tell me how to do this without having to do any VB as I know nothing in that area. I am a rank beginner in using Access. I have created a database consisting of student...
2
by: Sara | last post by:
I have followed instructions on the http://allenbrowne.com/tips.html for limiting a report to a date range. At the bottom there is a note that says You will end up using this form for all sorts...
2
by: Heather | last post by:
I want to create a report that shows the percent of safety audits complete by each individual shift, based on the safety audit date. The user has to put in the dates they want the report to pull...
0
by: Bill | last post by:
I've searched comp.databases.ms-access for a solution and found help but still haven't got my problem solved. I want to record weekly attendance and print an attendance "check off" sheet where...
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...
3
by: Eugenio | last post by:
Hello everybody, I'm new to this forum, so sorry if i post something that has been already answered althought i couldn't find it in search. Anyway, there it goes: i have a search system which...
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...
6
patjones
by: patjones | last post by:
Good afternoon: This seems like it shouldn't be hard, and then again this is how so many problems seem at the outset. My situation is this: I have a report called rptMain319, which is based...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.