Newbie to Combo Box and Reports

J

JAJansenJr

I have a combo box set to display all purchase order numbers in a table. The
combo box gets the purchase order numbers from the table and successfully
displays these in the drop down box. What I would like to have is a report
which will display all the records containing the purchase order number
selected by the combo box, with the option to print the report. I'm totally
new to Access 2007 and have not found a way to do this. This is surprising
because I would imagine displaying a report based on a particular purchase
order number (or other criteria) should be a pretty basic kind of report.
Any and all help in finding a way to do this sincerely appreciated.
 
J

JAJansenJr

This is a great example to obtain information between two dates. What I want
to do is to retrieve records containing the same Purchase Order number. The
same purchase order number can cover several records as each record describes
item(s) received from a given manufacturer. The reason for wanting a report
of this kind is to review the items a given purchase order number covered.

Another report I'd like to generate is to review all items ordered from a
given manufacturer. This would be useful in planning for a future order,
i.e. you would have some idea of what you were able to order from a given
manufacturer previously.

Another report that would be useful would be to generate a report showing
all the records for a given item. This would also be useful in planning for
a future order, i.e. you would have some idea if more than one manufacturer
can supply a given item.

I had no trouble creating a combo box to show all the purchase order numbers
from the table. Where I'm stuck is knowing how to take the selected purchase
order number and using this value as a key to generate a report containing
all records containing this key.

I'm searching both the Access 2007 help site as well as other tutorials
located using a Google search, but so far haven't been able to find a way to
do what I would like to do, as described in the foregoing.

Thanks for your reply. If you have any other suggestions these will be
appreciated and gratefully received!
 
K

Ken Sheridan

Restricting a report's results on the basis of a single criterion can be done
either by using a parameter in the report's RecordSource query, e.g. by
putting the following in the 'criteria' row of the purchase order number
column in query design view:

Forms!YourForm!cboPurchaseOrderNumber

where YourForm is the name of the form and cboPurchaseOrderNumber the name
of the combo box. Its then just a case of opening the report with a button
on the form.

Alternatively the report can be designed to return all records by default
and restricted by means of the WhereCondition argument of the OpenReport
method, in which case the code in the Click event procedure of the button on
the form to open the report in print preview would go like this:

Dim strCriteria As String

strCriteria = "[PurchaseOrderNumber] = " & Me.cboPurchaseOrderNumber

DoCmd.OpenReport "YourReportNameGoesHere", _
View:=acViewPreview, _
WhereCondition:=strCriteria

This assumes that the PurchaseOrderNumber column is a number data type. If
its text data type you'd use:

strCriteria = "[PurchaseOrderNumber] = """ & Me.cboPurchaseOrderNumber & """"

One thing which does puzzle me slightly is that you say "each record
describes item(s)", suggesting that a row could contain more than one type of
item. A row should only contain one type of item, so if a manufacture
supplies more than one type of item these would appear in separate rows.
This can be illustrated with a simple query on the sample Northwind database
which comes with Access. If you run this you'll see that there are multiple
rows returned per customer, one for each product supplied to them:

SELECT Customers.CustomerID, Customers.CompanyName,
Products.ProductName, COUNT(*) AS NumberSupplied
FROM Products INNER JOIN ((Customers INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID)
INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID)
ON Products.ProductID = [Order Details].ProductID
GROUP BY Customers.CustomerID, Customers.CompanyName,
Products.ProductName;

Ken Sheridan
Stafford, England
 
J

JAJansenJr

This is very helpful. I am so new to Access 2007 I am not sure of the
specific steps I need to take. I would like to try the first suggestion
(putting the following in the "criteria" row etc). Could you elaborate on
the exact steps I need to take to do this. Thanks very much!

Ken Sheridan said:
Restricting a report's results on the basis of a single criterion can be done
either by using a parameter in the report's RecordSource query, e.g. by
putting the following in the 'criteria' row of the purchase order number
column in query design view:

Forms!YourForm!cboPurchaseOrderNumber

where YourForm is the name of the form and cboPurchaseOrderNumber the name
of the combo box. Its then just a case of opening the report with a button
on the form.

Alternatively the report can be designed to return all records by default
and restricted by means of the WhereCondition argument of the OpenReport
method, in which case the code in the Click event procedure of the button on
the form to open the report in print preview would go like this:

Dim strCriteria As String

strCriteria = "[PurchaseOrderNumber] = " & Me.cboPurchaseOrderNumber

DoCmd.OpenReport "YourReportNameGoesHere", _
View:=acViewPreview, _
WhereCondition:=strCriteria

This assumes that the PurchaseOrderNumber column is a number data type. If
its text data type you'd use:

strCriteria = "[PurchaseOrderNumber] = """ & Me.cboPurchaseOrderNumber & """"

One thing which does puzzle me slightly is that you say "each record
describes item(s)", suggesting that a row could contain more than one type of
item. A row should only contain one type of item, so if a manufacture
supplies more than one type of item these would appear in separate rows.
This can be illustrated with a simple query on the sample Northwind database
which comes with Access. If you run this you'll see that there are multiple
rows returned per customer, one for each product supplied to them:

SELECT Customers.CustomerID, Customers.CompanyName,
Products.ProductName, COUNT(*) AS NumberSupplied
FROM Products INNER JOIN ((Customers INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID)
INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID)
ON Products.ProductID = [Order Details].ProductID
GROUP BY Customers.CustomerID, Customers.CompanyName,
Products.ProductName;

Ken Sheridan
Stafford, England

JAJansenJr said:
This is a great example to obtain information between two dates. What I want
to do is to retrieve records containing the same Purchase Order number. The
same purchase order number can cover several records as each record describes
item(s) received from a given manufacturer. The reason for wanting a report
of this kind is to review the items a given purchase order number covered.

Another report I'd like to generate is to review all items ordered from a
given manufacturer. This would be useful in planning for a future order,
i.e. you would have some idea of what you were able to order from a given
manufacturer previously.

Another report that would be useful would be to generate a report showing
all the records for a given item. This would also be useful in planning for
a future order, i.e. you would have some idea if more than one manufacturer
can supply a given item.

I had no trouble creating a combo box to show all the purchase order numbers
from the table. Where I'm stuck is knowing how to take the selected purchase
order number and using this value as a key to generate a report containing
all records containing this key.

I'm searching both the Access 2007 help site as well as other tutorials
located using a Google search, but so far haven't been able to find a way to
do what I would like to do, as described in the foregoing.

Thanks for your reply. If you have any other suggestions these will be
appreciated and gratefully received!
 
K

Ken Sheridan

1. Firstly create the unbound form with the combo box to select the purchase
order number. Save it under a suitable name such as frmPurchaseOrderDlg.

2. Next you need to create the query on which the report will be based.
Open the query designer and add the necessary table or tables, joining the
tables on the relevant columns if there is more than one table.

3. Next add the relevant columns (fields) from the tables by dragging them
into the columns of the design grid.

4. In the 'criteria' row of the purchase order number column enter the
reference to the combo box on the form you created in step 1 like so:

Forms!frmPurchaseOrderDlg!cboPurchaseOrderNumber

using whatever names you've decided to call the form and combo box if
different from my example. The initial 'Forms' stays the same, though,
whatever the name of the form or control; it’s a reference to the Forms
collection. Save the query.

5. You can now test the query by opening the form you created in step 1 and
selecting a purchase order number in the combo box. Then, with the form
still open, open the query. All being well it should return the rows for the
selected purchase order number only.

6. If the query is working properly create a report based on it, which you
can do using the report wizard. Save the report.

7. Go back to the form you created in step 1 and, in form design view, add
two command buttons, using the button wizard, one to print the report the
other to preview it. Save the form.

To open the report you simply open the form, select a purchase order number
and click one of the buttons.

You can if you wish have multiple controls on the form and reference them in
different columns of the query, so you can restrict the report's results on
the basis of as few or as many of the controls on the form in combination as
you wish. Lets take it one step at a time, however, and get it working with
just one control first.

Ken Sheridan
Stafford, England

JAJansenJr said:
This is very helpful. I am so new to Access 2007 I am not sure of the
specific steps I need to take. I would like to try the first suggestion
(putting the following in the "criteria" row etc). Could you elaborate on
the exact steps I need to take to do this. Thanks very much!

Ken Sheridan said:
Restricting a report's results on the basis of a single criterion can be done
either by using a parameter in the report's RecordSource query, e.g. by
putting the following in the 'criteria' row of the purchase order number
column in query design view:

Forms!YourForm!cboPurchaseOrderNumber

where YourForm is the name of the form and cboPurchaseOrderNumber the name
of the combo box. Its then just a case of opening the report with a button
on the form.

Alternatively the report can be designed to return all records by default
and restricted by means of the WhereCondition argument of the OpenReport
method, in which case the code in the Click event procedure of the button on
the form to open the report in print preview would go like this:

Dim strCriteria As String

strCriteria = "[PurchaseOrderNumber] = " & Me.cboPurchaseOrderNumber

DoCmd.OpenReport "YourReportNameGoesHere", _
View:=acViewPreview, _
WhereCondition:=strCriteria

This assumes that the PurchaseOrderNumber column is a number data type. If
its text data type you'd use:

strCriteria = "[PurchaseOrderNumber] = """ & Me.cboPurchaseOrderNumber & """"

One thing which does puzzle me slightly is that you say "each record
describes item(s)", suggesting that a row could contain more than one type of
item. A row should only contain one type of item, so if a manufacture
supplies more than one type of item these would appear in separate rows.
This can be illustrated with a simple query on the sample Northwind database
which comes with Access. If you run this you'll see that there are multiple
rows returned per customer, one for each product supplied to them:

SELECT Customers.CustomerID, Customers.CompanyName,
Products.ProductName, COUNT(*) AS NumberSupplied
FROM Products INNER JOIN ((Customers INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID)
INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID)
ON Products.ProductID = [Order Details].ProductID
GROUP BY Customers.CustomerID, Customers.CompanyName,
Products.ProductName;

Ken Sheridan
Stafford, England

JAJansenJr said:
This is a great example to obtain information between two dates. What I want
to do is to retrieve records containing the same Purchase Order number. The
same purchase order number can cover several records as each record describes
item(s) received from a given manufacturer. The reason for wanting a report
of this kind is to review the items a given purchase order number covered.

Another report I'd like to generate is to review all items ordered from a
given manufacturer. This would be useful in planning for a future order,
i.e. you would have some idea of what you were able to order from a given
manufacturer previously.

Another report that would be useful would be to generate a report showing
all the records for a given item. This would also be useful in planning for
a future order, i.e. you would have some idea if more than one manufacturer
can supply a given item.

I had no trouble creating a combo box to show all the purchase order numbers
from the table. Where I'm stuck is knowing how to take the selected purchase
order number and using this value as a key to generate a report containing
all records containing this key.

I'm searching both the Access 2007 help site as well as other tutorials
located using a Google search, but so far haven't been able to find a way to
do what I would like to do, as described in the foregoing.

Thanks for your reply. If you have any other suggestions these will be
appreciated and gratefully received!
:

Hi JA,

You can try this tutorial:

http://www.accessmvp.com/TWickerath/downloads/customdialogbox.zip


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

I have a combo box set to display all purchase order numbers in a table. The
combo box gets the purchase order numbers from the table and successfully
displays these in the drop down box. What I would like to have is a report
which will display all the records containing the purchase order number
selected by the combo box, with the option to print the report. I'm totally
new to Access 2007 and have not found a way to do this. This is surprising
because I would imagine displaying a report based on a particular purchase
order number (or other criteria) should be a pretty basic kind of report.
Any and all help in finding a way to do this sincerely appreciated.
 
T

Tom Wickerath

Hi JA,
This is a great example to obtain information between two dates. What I want
to do is to retrieve records containing the same Purchase Order number.

You will use the same logic shown in the article, except that your situation
will be easier, since you are not querying between a range of values. In your
case, the combo box to select a City (ie. select one parameter) would be more
analogous to selecting (in an unbound combo box) or entering directly (in an
unbound text box) the purchase order number.
Another report I'd like to generate is to review all items ordered from a
given manufacturer.

Use the same idea. For a list of manufacturers, I'd probably use a combo box
with a RowSource based on a lookup table. That way, people could select the
manufacturer from a list, instead of having to spell the manufacturer's name
correctly in a text box (or fragment of a manufacturer's name, if you
concatenated the wildcard search character (*).
Another report that would be useful would be to generate a report showing
all the records for a given item.

This is very do-able, using the material I have supplied as a guide. It's
not intended to be an exact fit for any one purpose. Try creating the sample
from scratch, so that you can understand how it works. Then try applying the
same logic to your particular situation.

Here are links to my QBF samples. if you are okay with using some Visual
Basic for Applications (VBA) code:

http://www.accessmvp.com/TWickerath/downloads/elements.zip

http://www.accessmvp.com/TWickerath/downloads/Chap08QBF.zip


The first one shown above, Elements.zip, is about as easy as they get. Here,
I have shown just a single multi-select list box control, to allow one to
select one or more elements from the periodic table in the list. Hey, I'm a
chemist, so this example was natural for me! Anyway, you can make a
continuous selection by holding down the Shift key, or a discontinuous
selection by using the Control key.

The Chap08QBF sample is the basis for all of my QBF forms. This sample came
from Scott Barker's book titled "Access 2000 Power Programming". It includes
the original form/subform, as well as my modifications to these two forms.

If you'd like to learn how these work, I have a Word document and sample
Access database available here:

http://www.seattleaccess.org/downloads.htm

Look for:
Query By Form - Multi Select
Tom Wickerath, February 12, 2008

If you are new to VBA code, then your first stop should be to check out
these two documents:

http://www.seattleaccess.org/downloads.htm
DAO - Back To Basics Compilation/Demo
by Tom Wickerath, Jan/Feb 2007

and

Access Basics by Crystal
http://www.accessmvp.com/Strive4Peace/Index.htm


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

JAJansenJr

:
Thanks to both Tom and Ken. I'll be trying your ideas out.

I worked with a Microsoft support engineer who did not provide a complete
solution but from what he suggested I then decided to use the Access help
system and searched for "where condition" and
then "Open Report Macro Action". This latter help page provided an example
that matched my need and described the exact "Where Condition" clause I
needed for the Open Report Macro. Everything now works perfectly.
 
J

JAJansenJr

Obviously in my last message I should have edited out ""Tom Wickerath"
wrote:". Sorry for missing that.

I have one last issue I need to find a solution for. The combo box shows
the PO number for every record. There are a large number of records in the
table the combo box draws from. Multiple records have the same PO number.

I need to find a way to search the table record by record and build up a
second table of unique PO numbers. The combo box then needs to draw from the
table of unique PO numbers.

Is there a simple way to build this second table of unique PO numbers? Or
is there another way to supply the combo box with the list of unique PO
numbers.

Thanks for all the help!
 
T

Tom Wickerath

Hi JA,

I certainly hope you didn't have to pay too much for that support engineer's
help. The newsgroups are free, and I'd like to believe that we provide high
quality support. (The samples I pointed you to all include the optional
WhereCondition statement in a DoCmd.OpenReport statement).

There are two ways of solving your last issue. The easiest way involves
adding one word to the Structured Query Language (SQL) statement that serves
as the rowsource for your combo box. This word would be: DISTINCT. If the row
source looks like this:

Select [TableName].[FieldName] from [TableName] order by [FieldName]

where TableName is the name of the applicable table, and FieldName is the
name of the field that contains your PO number. In that case, you can simply
add this keyword as follows:

Select DISTINCT [TableName].[FieldName] from [TableName] order by [FieldName]

If the row source is based on a saved query, then open the query in design
view. Then click on View | SQL View. Insert the DISTINCT keyword as indicated
above, just after the SELECT keyword. Save your changes, close the query, and
test.

However, while the above method is the easiest, it is *not* the most
efficient, because it will result in an automatic table scan. A table scan
means that all records must be read. If you have a network wire that
separates your PC from the data file, then you'll want to design efficiently
to avoid table scans. In that case, you very like would want to create a
lookup table, with the unique PO Number in the new table either set as a
primary key, or indexed uniquely. You would then join this field to your
existing PO Number field in a one-to-many relationship. So, what you need in
this case is a new query that serves as the source of data for a Make-Table
query. Something like this (as before):

Select DISTINCT [TableName].[FieldName] from [TableName] order by [FieldName]

You would then save this query as a temporary object (you can delete it when
you are done). Create a Make-Table query that uses this new query as a source
of data. See the following link for help on Action Queries, of which a
Make-Table query is one type.

http://office.microsoft.com/en-us/access/CH063653171033.aspx

You want the third item listed: "Create a table from another table with a
query". Alternatively, you could create a new table by from scratch, and then
use an Append query to add records to it. The Append query would use the same
temporary query that includes the DISTINCT (or a GROUP BY) clause as it's
source of data.

Note that a Make-Table query will not add any indexes; you'll need to open
the resulting table in design view and index the PO Number field
appropriately.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

JAJansenJr

Hi Tom,

The support engineer is free for 90 days from the date of the first support
request. The support here is outstanding but I'm going after every channel
that can provide help.

Turned out the SELECT DISTINCT worked.

I shut down the machine and, somehow, managed to not save my work so the
report shows no entries again! It may be due to the fact that I programmed a
"Quit" button to terminate the application and the "quit" macro may have quit
alright but without saving various changes.

So tomorrow it's back to the MS Support Engineer to see if I can get back to
where I was when things worked.

I do intend to try every suggestion presented here, and hope to be back to
let you know what I've been able to do.

Thanks again to everyone. This early breaking in on a new software
development tool is pretty demanding but every time you get something else to
work it gets increasingly more easy to work with.



Tom Wickerath said:
Hi JA,

I certainly hope you didn't have to pay too much for that support engineer's
help. The newsgroups are free, and I'd like to believe that we provide high
quality support. (The samples I pointed you to all include the optional
WhereCondition statement in a DoCmd.OpenReport statement).

There are two ways of solving your last issue. The easiest way involves
adding one word to the Structured Query Language (SQL) statement that serves
as the rowsource for your combo box. This word would be: DISTINCT. If the row
source looks like this:

Select [TableName].[FieldName] from [TableName] order by [FieldName]

where TableName is the name of the applicable table, and FieldName is the
name of the field that contains your PO number. In that case, you can simply
add this keyword as follows:

Select DISTINCT [TableName].[FieldName] from [TableName] order by [FieldName]

If the row source is based on a saved query, then open the query in design
view. Then click on View | SQL View. Insert the DISTINCT keyword as indicated
above, just after the SELECT keyword. Save your changes, close the query, and
test.

However, while the above method is the easiest, it is *not* the most
efficient, because it will result in an automatic table scan. A table scan
means that all records must be read. If you have a network wire that
separates your PC from the data file, then you'll want to design efficiently
to avoid table scans. In that case, you very like would want to create a
lookup table, with the unique PO Number in the new table either set as a
primary key, or indexed uniquely. You would then join this field to your
existing PO Number field in a one-to-many relationship. So, what you need in
this case is a new query that serves as the source of data for a Make-Table
query. Something like this (as before):

Select DISTINCT [TableName].[FieldName] from [TableName] order by [FieldName]

You would then save this query as a temporary object (you can delete it when
you are done). Create a Make-Table query that uses this new query as a source
of data. See the following link for help on Action Queries, of which a
Make-Table query is one type.

http://office.microsoft.com/en-us/access/CH063653171033.aspx

You want the third item listed: "Create a table from another table with a
query". Alternatively, you could create a new table by from scratch, and then
use an Append query to add records to it. The Append query would use the same
temporary query that includes the DISTINCT (or a GROUP BY) clause as it's
source of data.

Note that a Make-Table query will not add any indexes; you'll need to open
the resulting table in design view and index the PO Number field
appropriately.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

JAJansenJr said:
Obviously in my last message I should have edited out ""Tom Wickerath"
wrote:". Sorry for missing that.

I have one last issue I need to find a solution for. The combo box shows
the PO number for every record. There are a large number of records in the
table the combo box draws from. Multiple records have the same PO number.

I need to find a way to search the table record by record and build up a
second table of unique PO numbers. The combo box then needs to draw from the
table of unique PO numbers.

Is there a simple way to build this second table of unique PO numbers? Or
is there another way to supply the combo box with the list of unique PO
numbers.

Thanks for all the help!
 
T

Tom Wickerath

Turned out the SELECT DISTINCT worked.

Okay, but I think you would be better off in the long-run to create a lookup
table, so as to prevent reading every record in the (larger) table, just to
populate your combo box.

I shut down the machine and, somehow, managed to not save my work so the
report shows no entries again!

Hmmm.....possibly related?

Losing data when you close a form
http://allenbrowne.com/bug-01.html

Thanks again to everyone. This early breaking in on a new software
development tool is pretty demanding but every time you get something else to
work it gets increasingly more easy to work with.

Ah! This is a clear sign that you are well on your way to becoming an
"Access Junkie". You are being assimilated. Resistance is futile! <smile>


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top