Kamis, 23 Oktober 2014

[MS_AccessPros] Re: How to enter different product in the same carton

 

John,


First of all thanks indeed for being so supportive and generous for this help and guidance.

As you pointed out why i am getting ClientName from tbl CollectionVoucher i removed it from it, as it was my mistake while you told me before no table should have duplicate fields RULE NO. 1, only Pkey's can be part of other tables.

Then i modified your both queries slightly after removing ClientName from tbl CollectionVoucher.

qryGroupCartons:
SELECT CollectionVoucher.ConsigneeID, CollectionVoucher.ConsignmentNo, CollectionVoucher.ClientCIN, CollectionVoucher.Destination, Sum(CollectionVoucher.WeightOfCarton) AS Weight, CollectionVoucher.ExportDocs, CollectionVoucher.CartonNo, IIf(IsNumeric(Left(CollectionVoucher.CartonSuffix,1)),"",Left(CollectionVoucher.CartonSuffix,1)) AS CartonSuffix
FROM CollectionVoucher
WHERE (((CollectionVoucher.ConsignmentNo)=[Forms]![Dialog Consignment Delivery Note]![cmbConsignmentNo]))
GROUP BY CollectionVoucher.ConsigneeID, CollectionVoucher.ConsignmentNo, CollectionVoucher.ClientCIN, CollectionVoucher.Destination, CollectionVoucher.ExportDocs, CollectionVoucher.CartonNo, IIf(IsNumeric(Left(CollectionVoucher.CartonSuffix,1)),"",Left(CollectionVoucher.CartonSuffix,1));


Consignment Delivery Note Query:
SELECT qryGroupCartons.ConsignmentNo, qryGroupCartons.ClientCIN, Clients.ClientName, Consignee.ConsigneeName, qryGroupCartons.Destination, Count(qryGroupCartons.CartonNo) AS TotalCartons, Sum(qryGroupCartons.Weight) AS TotalWeight, qryGroupCartons.ExportDocs
FROM (Consignee INNER JOIN qryGroupCartons ON Consignee.ConsigneeID = qryGroupCartons.ConsigneeID) INNER JOIN Clients ON (Consignee.ConsigneeID = Clients.ConsigneeID) AND (qryGroupCartons.ClientCIN = Clients.ClientCIN)
GROUP BY qryGroupCartons.ConsignmentNo, qryGroupCartons.ClientCIN, Clients.ClientName, Consignee.ConsigneeName, qryGroupCartons.Destination, qryGroupCartons.ExportDocs;

-----------------------------------------
Now one thing i'm not getting that in qryGroupCartons last line of sql
IIf(IsNumeric(Left(CollectionVoucher.CartonSuffix,1)),"",Left(CollectionVoucher.CartonSuffix,1));

Why you used IsNumeric ?
Field CartonSuffix is Text, and its Default Value is set to 0 (Should it be ZERO ?)

Secondly, now the report is OK, BUT i'm confused in CartonSuffix. On my previously entered data for ConsignmentNo 2014-A-05, ClientCIN 15 has delivered 81 cartons.

CartonNo 1 - 36 have been received against DeliveryVr 075
CartonNo 1 - 45 have been received against DeliveryVr 084

Duplicate CartonNo are from 1 - 36
If i assign CartonSuffix for these 1 - 36 duplicate cartons as below the report is OK.

CartonNo          CartonSuffix
1                      A
1                      B
2                      A
2                      B
up to CartonNo 36
36                    A
36                    B
Remaining
37                    0
38                    0
39                    0
40                    0
41                    0
42                    0
43                    0
44                    0
45                    0
But if i assign CartonSuffix as 0,1 OR 1,2 for CartonNo 1 -36, remaining 37 - 45 CartonSuffix as 0, then report shows Total Cartons for this Client = 45.

In this scenario what way i should adopt to assign CartonSuffix?

The delay in replying you was this issue, which i was checking.

Once lot of thanks up to here.

Khalid     




---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

Khalid-

Sorry I missed the bracket!

I assume you're now also using CartonSuffix with letters to indicate cartons moved from another assignment with duplicates.  For example, if a carton 1 was moved, its CartonSuffix would be A1.  If a moved Carton has multiple products, then you would use A2, A3, etc.

First, build a query on CollectionVoucher that "pre-groups" the cartons containing multiple products:

qryGroupCartons:
SELECT ConsigneeID, ConsignmentNo, ClientCIN, ClientName, Destination, Sum(WeightOfCarton) As Weight, ExportDocs, CartonNo, IIf(IsNumeric(Left(CollectionVoucher.CartonSuffix, 1)), "", Left(CollectionVoucher.CartonSuffix, 1)) As CartonSuffix
FROM CollectionVoucher
WHERE (((CollectionVoucher.ConsignmentNo)=[Forms]![Dialog Consignment Delivery Note]![cmbConsignmentNo]))
GROUP BY ConsigneeID, ConsignmentNo, ClientCIN, ClientName, Destination, ExportDocs, CartonNo, IIf(IsNumeric(Left(CollectionVoucher.CartonSuffix, 1)), "", Left(CollectionVoucher.CartonSuffix, 1));

Now substitute this query in your final query:

SELECT qryGroupCartons.ConsignmentNo, qryGroupCartons.ClientCIN, qryGroupCartons.ClientName, Consignee.ConsigneeName, qryGroupCartons.Destination, Count(qryGroupCartons.CartonNo) AS TotalCartons, Sum(qryGroupCartons.Weight) AS TotalWeight, qryGroupCartons.ExportDocs
FROM Consignee INNER JOIN qryGroupCartons ON Consignee.ConsigneeID = qryGroupCartons.ConsigneeID
GROUP BY qryGroupCartons.ConsignmentNo, qryGroupCartons.ClientCIN, qryGroupCartons.ClientName, Consignee.ConsigneeName, qryGroupCartons.Destination, qryGroupCartons.ExportDocs;

The first query groups the rows in CollectionVoucher by CartonNo and "" when the CartonSuffix is just a number and by CartonNo and the letter when the CartonNo contains a letter indicating a duplicate CartonNo.  Your final query now counts the rows grouped by the first query.

By the way, why are you getting ClientName from CollectionVoucher?  I would think ClientName would appear in the Clients table linked by ClientCIN.  When you introduce a duplicate field like this, you make your data subject to errors if the name gets misspelled when entered in the second table.  This would mean an additional join to the Clients table to get the name, but you avoid any data entry errors.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Oct 23, 2014, at 8:41 AM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John,

Sorry that i was missing left bracket [ before CartonSuffix. Its OK now.

Now coming to one of a report "Consignment Delivery Note" its Record Source is a query with sql:

SELECT CollectionVoucher.ConsignmentNo, CollectionVoucher.ClientCIN, CollectionVoucher.ClientName, Consignee.ConsigneeName, CollectionVoucher.Destination, Count(CollectionVoucher.CartonNo) AS TotalCartons, Sum(CollectionVoucher.WeightOfCarton) AS TotalWeight, CollectionVoucher.ExportDocs
FROM Consignee INNER JOIN CollectionVoucher ON Consignee.ConsigneeID = CollectionVoucher.ConsigneeID
GROUP BY CollectionVoucher.ConsignmentNo, CollectionVoucher.ClientCIN, CollectionVoucher.ClientName, Consignee.ConsigneeName, CollectionVoucher.Destination, CollectionVoucher.ExportDocs
HAVING (((CollectionVoucher.ConsignmentNo)=[Forms]![Dialog Consignment Delivery Note]![cmbConsignmentNo]));

I have entered some test data for ClientCIN 2

CartonNo           CartonSuffix

1                       1
2                       1
3                       1
3                       2
3                       3
CartonNo 3 containing three different Products   

Now on the Report i need that it should show me Total Cartons for this Client THREE i.e CartonNo 1,2 & 3
but i get Total Cartons = 5 which is count of CartonNo

Sorting and Grouping is of Report is:
Destination --- Group Header   -- Yes
ClientCIN   --- Group Header   --  No
TotalCartons ---- Group Header   -- No

Where i'm wrong? and what should i do to get Report as i need?
table CollectionVoucher has Pkey ConsignmentNo, ClientCIN, CartonNo and CartonSuffix

Khalid     
 
 


---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

Khalid-

OK, my mistake.  Something is missing in your criteria.  Try adding a Debug.Print stLinkCriteria after you assign the predicate.  You can see the result in the Immediate Window.  (CTRL+G)

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)


P.S. When replying on the web, click Show Message History at the bottom of the message area so I can see previous replies in email.  I have to keep going back to the group website to look at previous answers.

On Oct 21, 2014, at 2:48 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John, 

No! ClientCIN is number and CartonNo is number.

ConsignmentNo is Text
DeliveryVr is Text
CartonSuffix is Text

Khalid


__._,_.___

Posted by: khalidtanweerburrah@yahoo.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (23)

.

__,_._,___

Tidak ada komentar:

Posting Komentar