two subforms

  • Thread starter Thread starter style45
  • Start date Start date
S

style45

I have two subforms created on a form that are almost identical except for
certain fields that contain different order details. I am trying to create a
report that will that will merge both these subforms into one report as one
order. Is there a way to do this?
 
There's a few ways to do this:

Solution A: Report with subreport
========================
You could create a subreport to handle the items from the 2nd related.
The subreport goes into the Group Footer section.
For info on how to pick up the subtotal from the subreport, see:
Bring the total from a subreport onto a main report
at:
http://allenbrowne.com/casu-18.html

Solution B: UNION query
==================
It is possible to combine the data from 2 tables into one long list by
writing a UNION query. Access can't do this graphically, so you will be
working in SQL View.

Solution C: Use one table, but 2 subforms
==============================
This may not be obvious, but it is generally my preferred solution. I
imagine you have a main form (such as a work order), with 2 subforms bound
to different tables (such as WorkOrderParts and WorkOrderLabor to handle the
2 kinds of related items.)

The trick is to combine these into one table. Fields:
WorkOrderDetailID AutoNumber primary key
WorkOrderTypeID Number 1=parts; 2=labor
Quantity Number hours or number used
PriceEach Currently hourly rate or price each
PartID foreign key to parts table (blank for labor)
EmployeeID foreign key to Employee table (blank for parts)
Descrip Text comments

Now you create 2 queries:
- one where WorkOrderTypeID = 1
- one where WorkOrderTypeID = 2
and these become the Record Source for your 2 subforms.
The interface reflects the way the user thinks about the data, but the data
structure behind it makes it easy to query the data and get the information
into a report.

There's no way for us to know which will be best for you, but (C) is my
preferred approach when appropriate.
 
Allen,

I am not sure if the description will fit what I am trying to accomplish,
listed below is my problem:
I have two order details possible another one.
Order Details 15% Rebate = 1
OrderDetailID, OrderID, ProductID, Quantity, Prices

Order Details LG Rebate = 2
OrderDetailID, OrderID, ProductID, Quantity, Prices, Customer

These two tables are almost the same except for different prices and LG
Rebate table added a column for customer.

Regards,
Kathi
 
I guess I didn't follow whey you could not have one table here, with fields:
OrderDetailID
OrderID
ProductID
Quantity
Prices
Customer (optional)
RebateLevel (1 or 2)
etc

In any case, if solution C did not suit, you still have the other 2 to
consider.
 
I guess I am trying to work with two OrderDetails with different prices and
qty, is this something I can accomplish.

OrderDetail ID == Rebate15%
OrderDetail ID == LGRebate
both of these order details goes to one order

Kathi


Allen said:
I guess I didn't follow whey you could not have one table here, with fields:
OrderDetailID
OrderID
ProductID
Quantity
Prices
Customer (optional)
RebateLevel (1 or 2)
etc

In any case, if solution C did not suit, you still have the other 2 to
consider.
[quoted text clipped - 19 lines]
 
So you expect 2 OrderDetails entries in one order?

That should be okay. (I assume it is a one-to-many relation.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

style45 via AccessMonster.com said:
I guess I am trying to work with two OrderDetails with different prices and
qty, is this something I can accomplish.

OrderDetail ID == Rebate15%
OrderDetail ID == LGRebate
both of these order details goes to one order

Kathi


Allen said:
I guess I didn't follow whey you could not have one table here, with
fields:
OrderDetailID
OrderID
ProductID
Quantity
Prices
Customer (optional)
RebateLevel (1 or 2)
etc

In any case, if solution C did not suit, you still have the other 2 to
consider.
[quoted text clipped - 19 lines]
one
order. Is there a way to do this?
 
Hi Allen,
I guess I am not getting this too easily and I am getting frustrated.

What I have are products with three different prices, what I would like to do
is in the form field to be able to use the drop down box and the unit price
will automatically be entered. Would you suggest that I have these table with
prices into one or three separate tables.

Please stir me into the right direction in how to set this up. Thank you.

Allen said:
So you expect 2 OrderDetails entries in one order?

That should be okay. (I assume it is a one-to-many relation.)
I guess I am trying to work with two OrderDetails with different prices and
qty, is this something I can accomplish.
[quoted text clipped - 24 lines]
 
If one product has many prices, there will be a one to many relation between
products and product prices.

The specifics will depend on why a product has multiple prices, e.g.:
Because you give your best customers better rates?
Or because a product could be sold in different ways (e.g. by volume or by
weight)?
Or because a product is sold in different sized packs?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

style45 via AccessMonster.com said:
Hi Allen,
I guess I am not getting this too easily and I am getting frustrated.

What I have are products with three different prices, what I would like to
do
is in the form field to be able to use the drop down box and the unit
price
will automatically be entered. Would you suggest that I have these table
with
prices into one or three separate tables.

Please stir me into the right direction in how to set this up. Thank you.

Allen said:
So you expect 2 OrderDetails entries in one order?

That should be okay. (I assume it is a one-to-many relation.)
I guess I am trying to work with two OrderDetails with different prices
and
qty, is this something I can accomplish.
[quoted text clipped - 24 lines]
one
order. Is there a way to do this?
 
Allen
We give a customers better rates.

Allen said:
If one product has many prices, there will be a one to many relation between
products and product prices.

The specifics will depend on why a product has multiple prices, e.g.:
Because you give your best customers better rates?
Or because a product could be sold in different ways (e.g. by volume or by
weight)?
Or because a product is sold in different sized packs?
Hi Allen,
I guess I am not getting this too easily and I am getting frustrated.
[quoted text clipped - 19 lines]
 
So, you will have a CustomerLevel table, with 3 records (one of each level
of customer.)

Your Customer table witll have a CustomerLevelID field, containing the 1, 2,
or 3 (which ever level the customer is on.)

Your ProductPrice table will have fields like this:
ProductID relates to Product.ProductID
CustomerLevelID relates to CustomerLevel.CustomerLevelID
Price Currency

So, each product will have 3 *records* in this table.
Now you ave able to lookup the price for any customer by examining their
CustomerLevelID, and getting that price.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

style45 via AccessMonster.com said:
Allen
We give a customers better rates.

Allen said:
If one product has many prices, there will be a one to many relation
between
products and product prices.

The specifics will depend on why a product has multiple prices, e.g.:
Because you give your best customers better rates?
Or because a product could be sold in different ways (e.g. by volume or by
weight)?
Or because a product is sold in different sized packs?
Hi Allen,
I guess I am not getting this too easily and I am getting frustrated.
[quoted text clipped - 19 lines]
one
order. Is there a way to do this?
 
Hi Allen,
It seems to be working fine -- you are a life saver. Can you also, tell me
how to get the price to come up automatically vs typing it each time for the
3 dfferent prices.

Thanks Kathi

Allen said:
So, you will have a CustomerLevel table, with 3 records (one of each level
of customer.)

Your Customer table witll have a CustomerLevelID field, containing the 1, 2,
or 3 (which ever level the customer is on.)

Your ProductPrice table will have fields like this:
ProductID relates to Product.ProductID
CustomerLevelID relates to CustomerLevel.CustomerLevelID
Price Currency

So, each product will have 3 *records* in this table.
Now you ave able to lookup the price for any customer by examining their
CustomerLevelID, and getting that price.
Allen
We give a customers better rates.
[quoted text clipped - 14 lines]
 
So, once you have entered the 3 prices for each product into the related
table, when you create an order for the customer you want to have the
software look up the current price to charge this client for the product,
based on their customer level?

Presumably you have a main form for the order, and a subform for the order
details (line items) - something like the Orders form in the Northwind
sample database that installs with Access. The main form will have a
CustomerID combo. Set up the combo's RowSource so it includes the
CustomerLevelID field, e.g.:
SELECT CustomerID, CustomerName, CustomerLevelID
FROM Customers ORDER BY CustomerName;
Don't forget to increase the combo's Column Count to 3.

Now in the AfterUpdate event procedure of the ProductID in the subform, you
can DLookup() the price in the ProductPrice table, based on the product and
the 3rd column of the CustomerID combo on the main form.

The AfterUpdate code will be something like this:
Dim strWhere As String
Dim varResult As Variant
varResult = Me.Parent!CustomerID.Column(2)
If IsNumeric(varResult) AND Not IsNull(Me.ProductID) Then
strWhere = "(ProductID = " & Me.ProductID & _
") AND (CustomerLevelID = " & varResult & ")"
varResult = DLookup("Price", "ProductPrice", strWhere)
If Not IsNull(varResult) Then
Me.Price = varResult
End If
End If

If that's a completely new idea, open the Orders Subform in Northwind, and
look at the code in the ProductID combo's event. It doesn't handle the bit
about differential pricing so it doesn't look at the customer combo on the
main form, but the idea of lookup is the same.

Alternatively, here's a description of DLookup():
http://allenbrowne.com/casu-07.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

style45 via AccessMonster.com said:
Hi Allen,
It seems to be working fine -- you are a life saver. Can you also, tell
me
how to get the price to come up automatically vs typing it each time for
the
3 dfferent prices.

Thanks Kathi

Allen said:
So, you will have a CustomerLevel table, with 3 records (one of each level
of customer.)

Your Customer table witll have a CustomerLevelID field, containing the 1,
2,
or 3 (which ever level the customer is on.)

Your ProductPrice table will have fields like this:
ProductID relates to Product.ProductID
CustomerLevelID relates to CustomerLevel.CustomerLevelID
Price Currency

So, each product will have 3 *records* in this table.
Now you ave able to lookup the price for any customer by examining their
CustomerLevelID, and getting that price.
Allen
We give a customers better rates.
[quoted text clipped - 14 lines]
one
order. Is there a way to do this?
 
Allen,
I can't seem to get the lookup price working and I have tried everything and
I don't know what I am doing wrong. Help.

Allen said:
So, once you have entered the 3 prices for each product into the related
table, when you create an order for the customer you want to have the
software look up the current price to charge this client for the product,
based on their customer level?

Presumably you have a main form for the order, and a subform for the order
details (line items) - something like the Orders form in the Northwind
sample database that installs with Access. The main form will have a
CustomerID combo. Set up the combo's RowSource so it includes the
CustomerLevelID field, e.g.:
SELECT CustomerID, CustomerName, CustomerLevelID
FROM Customers ORDER BY CustomerName;
Don't forget to increase the combo's Column Count to 3.

Now in the AfterUpdate event procedure of the ProductID in the subform, you
can DLookup() the price in the ProductPrice table, based on the product and
the 3rd column of the CustomerID combo on the main form.

The AfterUpdate code will be something like this:
Dim strWhere As String
Dim varResult As Variant
varResult = Me.Parent!CustomerID.Column(2)
If IsNumeric(varResult) AND Not IsNull(Me.ProductID) Then
strWhere = "(ProductID = " & Me.ProductID & _
") AND (CustomerLevelID = " & varResult & ")"
varResult = DLookup("Price", "ProductPrice", strWhere)
If Not IsNull(varResult) Then
Me.Price = varResult
End If
End If

If that's a completely new idea, open the Orders Subform in Northwind, and
look at the code in the ProductID combo's event. It doesn't handle the bit
about differential pricing so it doesn't look at the customer combo on the
main form, but the idea of lookup is the same.

Alternatively, here's a description of DLookup():
http://allenbrowne.com/casu-07.html
Hi Allen,
It seems to be working fine -- you are a life saver. Can you also, tell
[quoted text clipped - 26 lines]
 
Allen,

My Order Detail subform the Row Source has:
ProductID ProductName CustomerLevelID

I keeping getting a debug when I click on the drop down box for ProductName

Run-time error '2452':
The expression you entered has an invalid reference to the Parent propertly.

varResult = Me.Parent!CustomerID.Column(2)

Need your help again.
Allen,
I can't seem to get the lookup price working and I have tried everything and
I don't know what I am doing wrong. Help.
So, once you have entered the 3 prices for each product into the related
table, when you create an order for the customer you want to have the
[quoted text clipped - 40 lines]
 
Allen,
I am hung up on this formula:
varResult = DLookup("Price", "ProductPrice", strWhere)
Allen,

My Order Detail subform the Row Source has:
ProductID ProductName CustomerLevelID

I keeping getting a debug when I click on the drop down box for ProductName

Run-time error '2452':
The expression you entered has an invalid reference to the Parent propertly.

varResult = Me.Parent!CustomerID.Column(2)

Need your help again.
Allen,
I can't seem to get the lookup price working and I have tried everything and
[quoted text clipped - 5 lines]
 
Hi Allen,
Eliminate this theory, I just found out that on one of the levels there will
be different prices for different customers. So I need to go back to having
three subforms entirely.
Allen,
I am hung up on this formula:
varResult = DLookup("Price", "ProductPrice", strWhere)
[quoted text clipped - 15 lines]
 
The suggested structure does cope with different prices or different
customers. It does not use 3 subforms.

I don't have another suggestion.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

style45 via AccessMonster.com said:
Hi Allen,
Eliminate this theory, I just found out that on one of the levels there
will
be different prices for different customers. So I need to go back to
having
three subforms entirely.
Allen,
I am hung up on this formula:
varResult = DLookup("Price", "ProductPrice", strWhere)
[quoted text clipped - 15 lines]
one
order. Is there a way to do this?
 

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

Back
Top