MS Access Forum / Forms / May 2008
Form/Report Relationship
|
|
Thread rating:  |
Nancy - 29 Apr 2008 13:00 GMT My main form “ Purchase Order” has a subform “Order Details Subform”.
The Purchase Order table for the main form has the following fields: OrderID-Autonumber & Primary Key; Customer ID-number, Employee ID-number, Order Date-date, PO Number-number, etc.
The subform table has the following fields: (I do not have a primary key for Subform) OrderDetail ID-Autonumber, OrderID-number, Nomenclature-text, Part Number-number, etc.
My Master/Child link on the subform is OrderID. In the relationships page my Order Table is linked to my Order Table with a “1” on the Order Table “OrderID” and a “Many” on the Order Details Table “OrderID”.
When I fill out my Purchase Order form and subform and hit the preview report form for Purchase Order #1, all is fine and the report works great. The customer name, address, etc that is on the main form comes up fine along with all the subform information. When I complete a new purchuse order, ie PO #2 and hit the print preview for the report, the report now displays the new customer information from Purchase Order #2 and all of the data from the subform on Purchase Order #1 & #2. What am I doing wrong?
.
Carl Rapson - 29 Apr 2008 17:24 GMT Do the purchase orders display correctly in your form? If so, I'd say there's something wrong with either the RecordSource of the report or the way you're opening the report from the form. What is the report's RecordSource? How are you opening the report from your form?
If not, check the logic of your form - are you sure you're not overwriting PO #1 information with PO #2? Do both POs exist in your tables correctly?
Carl Rapson
> My main form " Purchase Order" has a subform "Order Details Subform". > [quoted text clipped - 25 lines] > > . Nancy - 29 Apr 2008 18:26 GMT Thanks for the response. I erased all entries at this point as I am still in the testing stage. I entered PO#1 with all the details. Saved the form and checked each table. All appears to be working correctly. I then opened the report and PO#1 shows up fine. I closed out of everything and reopened the PO Form. Entered PO#2. Check tables and all looks good. I then opened the Report and the only info showing now is the PO #1 info and no PO#2 Info. The report is based on a Query called the "Orders Query". I tried opening the report from the objects menu and from the command button I have installed on my form and I get the same results each way. Any other ideas? Could my query form be causing this? I ws thining about deleting the query and making a new one as the record souce to see if that is the problem. I am still pretty new to all this so any and all help is very much appricated.
> Do the purchase orders display correctly in your form? If so, I'd say > there's something wrong with either the RecordSource of the report or the [quoted text clipped - 35 lines] > > > > . strive4peace - 29 Apr 2008 21:00 GMT Hi Nancy,
can you please post the SQL for the query? from the menu --> View, SQL
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> Thanks for the response. I erased all entries at this point as I am still in > the testing stage. I entered PO#1 with all the details. Saved the form and [quoted text clipped - 48 lines] >>> >>> . Nancy - 30 Apr 2008 18:01 GMT Here is the SQL for the query. Thanks for any help you can give me. Everything else on the form/report works perfectly except for the printing and the ability to print one purchase order report for each purchase order. Right now it is printing the first purchase order number info on the report and the purchase order detail information from multiply purchase orders. Thanks.
SELECT Orders.OrderID AS Orders_OrderID, Orders.[Customer ID] AS [Orders_Customer ID], Employees.FirstName, Orders.OrderDate, Orders.PurchaseOrderNumber, Orders.ShipDate, [Shipping Methods].ShippingMethod, Orders.Taxes, Orders.Comment, Orders.[Core Charge], Orders.[Core Charge Amount], [Order Details].OrderDetailID, [Order Details].OrderID AS [Order Details_OrderID], [Order Details].Nomenclature, [Order Details].[Part Number], [Order Details].Quantity, [Order Details].UnitPrice, [Order Details].[Tail #], [Order Details].Condition, [Order Details].[Serial #], Customers.[Customer ID] AS [Customers_Customer ID], Customers.CompanyName, Customers.FirstName, Customers.LastName, Customers.BillingAddress, Customers.City, Customers.StateOrProvince, Customers.ZIPCode, Customers.Email, Customers.CompanyWebsite, Customers.PhoneNumber, Customers.FaxNumber, Customers.ShipAddress, Customers.ShipCity, Customers.ShipStateOrProvince, Customers.ShipZIPCode, Customers.ShipPhoneNumber, Customers.Notes, [Order Details Extended].Subtotal FROM ((Employees INNER JOIN (Customers INNER JOIN Orders ON Customers.[Customer ID]=Orders.[Customer ID]) ON Employees.EmployeeID=Orders.EmployeeID) INNER JOIN ([Order Details] INNER JOIN [Order Details Extended] ON [Order Details].OrderDetailID=[Order Details Extended].OrderDetailID) ON Orders.OrderID=[Order Details].OrderID) INNER JOIN [Shipping Methods] ON Orders.ShippingMethodID=[Shipping Methods].ShippingMethodID;
> Hi Nancy, > [quoted text clipped - 64 lines] > >>> > >>> . strive4peace - 30 Apr 2008 18:35 GMT Hi Nancy,
I formatted your SQL statement to be easier to read:
SELECT Orders.OrderID AS Orders_OrderID , Orders.[Customer ID] AS [Orders_Customer ID] , Employees.FirstName , Orders.OrderDate , Orders.PurchaseOrderNumber , Orders.ShipDate , [Shipping Methods].ShippingMethod , Orders.Taxes , Orders.Comment , Orders.[Core Charge] , Orders.[Core Charge Amount] , [Order Details].OrderDetailID , [Order Details].OrderID AS [Order Details_OrderID] , [Order Details].Nomenclature , [Order Details].[Part Number] , [Order Details].Quantity , [Order Details].UnitPrice , [Order Details].[Tail #] , [Order Details].Condition , [Order Details].[Serial #] , Customers.[Customer ID] AS [Customers_Customer ID] , Customers.CompanyName , Customers.FirstName , Customers.LastName , Customers.BillingAddress , Customers.City , Customers.StateOrProvince , Customers.ZIPCode , Customers.Email , Customers.CompanyWebsite , Customers.PhoneNumber , Customers.FaxNumber , Customers.ShipAddress , Customers.ShipCity , Customers.ShipStateOrProvince , Customers.ShipZIPCode , Customers.ShipPhoneNumber , Customers.Notes , [Order Details Extended].Subtotal FROM ((Employees INNER JOIN (Customers INNER JOIN Orders ON Customers.[Customer ID]=Orders.[Customer ID]) ON Employees.EmployeeID=Orders.EmployeeID) INNER JOIN ([Order Details] INNER JOIN [Order Details Extended] ON [Order Details].OrderDetailID =[Order Details Extended].OrderDetailID) ON Orders.OrderID=[Order Details].OrderID) INNER JOIN [Shipping Methods] ON Orders.ShippingMethodID =[Shipping Methods].ShippingMethodID;
I see there is no WHERE clause limiting the records to a particular purchase order ... are you using the Where clause of the OpenReport action in code to do this? If so, what is the code you use to launch the report?
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> Here is the SQL for the query. Thanks for any help you can give me. > Everything else on the form/report works perfectly except for the printing [quoted text clipped - 94 lines] >>>>> >>>>> . Nancy - 30 Apr 2008 19:11 GMT Thank you so much...
I am still very new to this so as to the Where clause. I guess I am not using it because don't know what it is. If you want to add it to the code and I can copy and paste into the SQL on my form and/ or report that would be fantastic!
Thank you so much for your help.
Nancy
> Hi Nancy, > [quoted text clipped - 167 lines] > >>>>> > >>>>> . strive4peace - 30 Apr 2008 19:52 GMT Hi Nancy,
please specify more information:
1. is PurchaseOrderNumber the field that you need to limit output for?
2. do you have a control on the form to specify which Purchase Order Number you want? - If so, what is the Name property of the control? - what is the name of your form?
3. what is the data type of PurchaseOrderNumber in your Orders table?
4. how are you currently generating the report?
for better understanding of the basics of Access, read this:
Access Basics by Crystal (Access MVP site) http://www.accessmvp.com/Strive4Peace/Index.htm 8-part free tutorial that covers essentials in Access
Warm Regards, Crystal
* (: have an awesome day :) *
> Thank you so much... > [quoted text clipped - 178 lines] >>>>>>> >>>>>>> . Nancy - 30 Apr 2008 21:04 GMT Thank you so much for your help. Here is what I have:
Purchase Order Form has: Order ID-Auto number CustomerID-Number Employee ID-Number Order Date-Date/Time Purchase Order Number-Text And some other Misc fields
The Purchase Order Details Sub-Form has: Order Detail ID-Auto-number OrderID-Number NomenclatureID-Number Nomenclature-Text Part Number-Number Quantity-Number And some misc fields
In design view in the subform property sheet the Master/Child link is: OrderID/OrderID
For each purchase order number, I may have five or six parts (nomenclature) that I am ordering from the supplier (customer). I need each purchase order number to print in a report with just the items purchased under that Purchase Order Number from that supplier (customer). For Example:
Purchase Order: 7155-4380 Supplier (Customer): Ram Aircraft Employee: Nancy Shipping Method: UPS Ground
Purchase Order Details Subform:
Nomenclature: Part Number Quantity Price Line Total Starter Ms74887-020 1 $3000.00 $3000.00 Starter Clamp MS12345-7 2 $3.50 $7.00 Starter Brush MSabcdef-123 6 $10.00 $60.00
Subtotal $3,067.00 Tax $214.69 Order Total $3281.69
End of Purchase Order 7155-4380
At this point I want to click on Preview Purchase Order Report and then print. The Purchase Order Report should only print this purchase order information. When I advance to the next purchase order on the purchase order form, i.e. 7156-4380 I want to do the same thing, only print the purchase order report with the details of purchase order 7156-4380. I hope this makes sense.
1. Purchase Order Number ifield is the one I need to limit, I think. 2. I am not sure I understand the question so here goes. On the Purchase Order form there is a text box for purchase order number that I manually input each time. The name of the form is Add an Order and Details. I would prefer to call it Purchase Order Form, but at this point I am afraid to change it. If you can get me going in the right direction I am sure I can figure out how to change the name so as not to screw up any underlying forms, tables, etc. 3. Data Type of the Purchase Order number is text. 4. I currently have a command button on the form that opens the preview report. On the properties page of the common button on the click event it says [Embedded Macro]. If there is a better way, I am all ears…
I started reviewing your site after the last post you did. Very interesting reading. I will continue to read it. As I said before, I am pretty new at this stuff so there is a learning curve. I have learned a lot so far and this site is amazing. And I plan to continue reading.
Thank you so very much for all your help.
> Hi Nancy, > [quoted text clipped - 206 lines] > >>>>>>> > >>>>>>> . strive4peace - 30 Apr 2008 21:59 GMT hi Nancy,
on second thought, you may have multiple purchase order numbers for different customers, so you would need to specify both CustomerID and Purchase Order Number
I would use code instead of a macro to generate the report
make sure that both CustomerID and Purchase Order Number are ON your report (CustomerID can be hidden if you do not want it to be visible --> set Visible = No)
'~~~~~~~~~~~~~~~ dim strWhere as string
strWhere = "CustomerID =" & me.CustomerID _ & " AND [Purchase Order Number] = '" _ & nz(me.Purchase_Order_Number,"") & "'"
docmd.OpenReport "Invoice", acViewNormal, ,strWhere
'~~~~~~~~~~~~~~~
"The name of the form is Add an Order and Details"
you can probably change the name of the form without any problem. Make sure everything is closed when you do this.
It is a good idea to avoid spaces and special characters in names so, instead of 'Purchase Order Form', I would suggest 'f_PurchaseOrder'
the f_ at the beginning indicates it is a form. Common naming convention uses 'frm' to preface form objects but I like 'f_' better ;)
when you make a form that will be used as a subform, I like to do this for the name:
f_Formname_sub
Where Formname includes the main form name it is designed for (if it is specific) and something about its use
For instance:
'f_PurchaseOrder_Details_sub'
~~~
glad you are enjoying Access Basics!
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> Thank you so much for your help. > Here is what I have: [quoted text clipped - 278 lines] >>>>>>>>> >>>>>>>>> . Nancy - 01 May 2008 03:20 GMT Thank you so much for your response. I don't want to sound stupid, but where exactly do I put the "Where Clause"? I assume in the SQL, but where? Beginning, end, etc. Never did this most of this stuff before so I am learning as I go along.
Also, I expect to have just one purchase order number for each transaction. I might have three transactions with the same customer in one day, but each would be a seperate purchase order number. And I might have several transactions during the day with several customers but each would be a seperate purchase order number. Having said that, do I need the customer ID included? And, is the Master/Child link correct with the orderID? Or should it be Purchase Order as the Master/Child?
Thank youuuuuuu......
> hi Nancy, > [quoted text clipped - 275 lines] > >>>>>> can you please post the SQL for the query? > >>>>>> from the menu --> View, SQL strive4peace - 01 May 2008 04:20 GMT Hi Nancy,
I am assuming that you have a command button to launch the report ... this code would go behind the form as an [Event Procedure] for the Click event of the command button
In this case, your query does not need a WHERE clause since strWhere is built to filter the data of the OpenReport action
the Purchase Order Number ... actually, looking at your structure again, I see that OrderID can be used instead of CustomerID and Purchase Order Number, so the code for the [Event Procedure] of your command button Click would be:
'~~~~~~~~~~~~~~~ dim strWhere as string
strWhere = "OrderID=" & me.OrderID
docmd.OpenReport "Invoice", acViewNormal, ,strWhere
'~~~~~~~~~~~~~~~
this simplifies it <smile>
the forms do not contain your data. TABLES are what holds the data. Forms are based on tables and can be used to display, edit and add data that is stored in tables. Whatever table the subform is based on has OrderID as a foreign key, so all the detail lines will be included
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> Thank you so much for your response. I don't want to sound stupid, but where > exactly do I put the "Where Clause"? I assume in the SQL, but where? [quoted text clipped - 290 lines] >>>>>>>> can you please post the SQL for the query? >>>>>>>> from the menu --> View, SQL Nancy - 01 May 2008 12:55 GMT Thanks for the Reply. I must be doing something wrong because I cannot get it to work. I went to design view of my form, highlighted the Preview Report command button to the properties page. On the click event I went to the code page and copy and pasted your response.
I changed the name of my report to “Invoice” so it would match your response. I placed the code between, “Private Sub and end sub statements”. Closed the page and made sure everything was saved. I then opened the PO form and hit the Preview report button and nothing at all would happen. I fiddled around for awhile and can’t seem to make the button work at all.
What am I doing wrong now? Please help me. Thank you so much.
> Hi Nancy, > [quoted text clipped - 277 lines] > >>>>>> =[Order Details Extended].OrderDetailID) > >>>>>> ON Orders.OrderID=[Order Details].OrderID) strive4peace - 01 May 2008 18:12 GMT Hi Nancy,
'~~~~~~~~~ Compile ~~~~~~~~~
Whenever you change code or references, your should always compile before executing.
from the menu in a VBE (module) window: Debug, Compile
fix any errors on the yellow highlighted lines
keep compiling until nothing happens (this is good!)
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> Thanks for the Reply. I must be doing something wrong because I cannot get > it to work. I went to design view of my form, highlighted the Preview Report [quoted text clipped - 290 lines] >>>>>>>> =[Order Details Extended].OrderDetailID) >>>>>>>> ON Orders.OrderID=[Order Details].OrderID) Rockn - 01 May 2008 21:50 GMT You need some way to link the data in the first sub-form to the purchase order you are working on. I think you answered your own question with "I do not have a primary key for Subform"
> My main form " Purchase Order" has a subform "Order Details Subform". > [quoted text clipped - 25 lines] > > . Nancy - 02 May 2008 12:42 GMT I tired the compile and debug and nothing seems to work. After the last suggestion, I went back and tried changing the Master/Child Link. I tried each suggestion that was offered and they all produced the same results. When I hit the preview report it shows all purchase order detail items under one purchase order number. Any other ideas, Please?
> You need some way to link the data in the first sub-form to the purchase > order you are working on. I think you answered your own question with "I do [quoted text clipped - 29 lines] > > > > . Nancy - 02 May 2008 13:03 GMT Any suggestions on what the primary key/foreign key should be for based on the tables listed above. Also, should this be a relationship probleM? Any suggestions on how they should be linked in relationships?
> You need some way to link the data in the first sub-form to the purchase > order you are working on. I think you answered your own question with "I do [quoted text clipped - 29 lines] > > > > . Nancy - 02 May 2008 15:15 GMT I must be doing something wrong. I still cannot get this to work right. Do you have any suggestions as to the primary key based on the table structure listed above. Could this be a relatiionship issue?
Thanks for any help at all
> You need some way to link the data in the first sub-form to the purchase > order you are working on. I think you answered your own question with "I do [quoted text clipped - 29 lines] > > > > . Nancy - 02 May 2008 20:09 GMT I must still be doing something wrong. Anymore suggestions? Could this be a relationship problem? Based on the table structure listed above do you have any recommendations about how best to link the data from the main form to the subform?
> You need some way to link the data in the first sub-form to the purchase > order you are working on. I think you answered your own question with "I do [quoted text clipped - 29 lines] > > > > . strive4peace - 02 May 2008 21:16 GMT Hi Nancy,
email me your database and specify the name of the form.
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> I must still be doing something wrong. Anymore suggestions? Could this be a > relationship problem? Based on the table structure listed above do you have [quoted text clipped - 34 lines] >>> >>> . strive4peace - 03 May 2008 10:00 GMT Hi Nancy,
First thing I did was look at you relationship diagram.
Move Order Details to the right of Orders so data flows from left to right
enforce Referential Integrity on the relationship from Shipping Methods to Orders
don't use lookup fields in your table design -- for instance, in Orders, change the Display control of EmployeeID to a textbox. forms are where you should have the combo boxes.
The Evils of Lookup Fields in Tables http://www.mvps.org/access/lookupfields.htm
Since you are using OrderID to link tour subform to your mainform, you need to put it ON your subform... you can set Visible = No so it does not show
~~
In the code behind the Purchase Order Report, you have an error
change If Not IsLoaded("Purchase Orders") Then to If Not CurrentProject.AllForms("Purchase Orders").IsLoaded Then or, if you rename the form --> If Not CurrentProject.AllForms("F_PurchaseOrder").IsLoaded Then
anyway, until you get the report working right, comment the lines for the Report_Open event ... put a single quote ' at the beginning of each statement so it turns green
you are getting the error about [Purchase Orders].PurchaseOrderID because that is how you have specified to group the report --
1. open the Sorting and Grouping window 2. click where [Purchase Orders].PurchaseOrderID is specified 3. drop the combobox and change the group field to --> Orders_OrderID
on F_PurchaseOrder
the reason your Preview Report button isn't doing anything is because you don't have it running any code.
1. from the design view of the form, turn on the Properties 2. click on the Preview Report command button 3. click on the Event tab of the Properties window 4. click in the property labeled --> On click 5. from the combobox, choose --> [Event Procedure] 6. click the builder button [...] to the right and insert this code between the procedure declaration Access provides for you and 'End Sub'
'~~~~~~~~~~~~~~~ Dim strWhere As String
strWhere = "Orders_OrderID=" & Me.OrderID
On Error Resume Next 'use this statement if you want the report to print 'DoCmd.OpenReport "Purchase Order", acViewNormal, , strWhere
'use this statement to preview the report DoCmd.OpenReport "Purchase Order", acViewPreview, , strWhere '~~~~~~~~~~~~~~~
put Orders_OrderID ON the report! It can have visible = No if you don't want it to show.
remove the captions on OrderID, OrderDate, etc in your table design. you should not use Captions in the table design -- when a table is opened directly, it should be done by a developer and the real fieldnames should show.
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> I must still be doing something wrong. Anymore suggestions? Could this be a > relationship problem? Based on the table structure listed above do you have [quoted text clipped - 34 lines] >>> >>> . Nancy - 03 May 2008 14:32 GMT Thank you so much. I will work on it today and let you know what happens.
Nancy
> Hi Nancy, > [quoted text clipped - 122 lines] > >>> > >>> . strive4peace - 03 May 2008 18:48 GMT Hi Nancy,
you're welcome ;)
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> Thank you so much. I will work on it today and let you know what happens. > [quoted text clipped - 126 lines] >>>>> >>>>> . Nancy - 03 May 2008 21:56 GMT Hi there. I made all the changes you suggested. I went step by step and saved each time a made a change and then checked to make sure everythingwas working. WOW! Thank you so much. The only thing I could not get to work was the preview report button. I did as you said and it just does not seem to work for me. I then deleted the button and used the command button wizard and it seems to work fine. As long as I first save the purchase order form and then hit the preview button it works great. I can live with this. Thank you oh so much....
> Hi Nancy, > [quoted text clipped - 141 lines] > >>>>> > >>>>> . strive4peace - 03 May 2008 22:18 GMT you're welcome, Nancy ;) happy to help
Warm Regards, Crystal
Access Basics 8-part free tutorial that covers essentials in Access http://www.accessmvp.com/Strive4Peace/Index.htm
* (: have an awesome day :) *
> Hi there. I made all the changes you suggested. I went step by step and > saved each time a made a change and then checked to make sure everythingwas [quoted text clipped - 4 lines] > form and then hit the preview button it works great. I can live with this. > Thank you oh so much....
|
|
|