Senin, 23 Februari 2015

Re: [MS_AccessPros] Report based on Crosstab query

 

John,

Thank you very much. Every thing is perfect and OK now.
I also added first Control on the report ClientCIN before ClientName.

I once again thank both of you (Duane & you) without help & guideness of both of you i could have not build this report.

Regards,
Khalid


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

Khalid-

To get rid of the year anomaly, you would have to change the query and some of the code.  Don't use the Consignment Number table at all.  Select the records based on the first four digits of then ConsignmentNo.

The revised query looks like this:

TRANSFORM Count(CollectionVoucher.CartonNo) AS CountOfCartonNo
SELECT tblConsignmentAlias.Level, Clients.ClientName, CollectionVoucher.ClientCIN, Count(CollectionVoucher.CartonNo) AS [Total Of CartonNo]
FROM Clients INNER JOIN (CollectionVoucher INNER JOIN tblConsignmentAlias ON CollectionVoucher.ConsignmentNo = tblConsignmentAlias.ConsignmentNo) ON Clients.ClientCIN = CollectionVoucher.ClientCIN
GROUP BY tblConsignmentAlias.Level, Clients.ClientName, CollectionVoucher.ClientCIN
ORDER BY CollectionVoucher.ClientCIN, tblConsignmentAlias.ColumnAlias
PIVOT tblConsignmentAlias.ColumnAlias In ("A","B","C","D","E","F","G","H");

In Module1, change the SQL in UpdateConsignmentAlias to:

   strSQL = "Delete * from tblConsignmentAlias"
   DoCmd.SetWarnings False
   DoCmd.RunSQL strSQL
   strSQL = "INSERT INTO tblConsignmentAlias (ConsignmentNo) " & _
        "SELECT DISTINCT ConsignmentNo " & _
        "FROM CollectionVoucher " & _
        "WHERE LEFT([ConsignmentNo], 4) = '" & [Forms]![frmRunCrosstab]![cboYear] & "' " & _
        "ORDER BY ConsignmentNo"

I was able to add a Sort on ClientCIN in the report (Use Sorting and Grouping) to change the output sequence.

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 Feb 23, 2015, at 12:01 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Duane,
Thanks once again for your Report. I have done some changes in the design as per my needs, like making Report Header, in Report Footer putting Totals of Cartons under each ConsignmentNo. Changing some Captions on the "frmRunCrosstab".

Although the report is perfect and i'm going to use it. You might have noticed in my data that in table "Consignment Number" for ConsignmentNo 2014-B-08 ExportDocs date is 15/01/15 that is why this ConsignmentNo is not displaying in Year 2014, but it appears in Year 2015. This situation might occur in future like ConsignmentNo is say 2015-A-10 and ExportDocs date is suppose 20/02/16.

For this i was thinking that should i add a new field like "ConsignmentYear" in table "Consignment Number" and while adding a new ConsignmentNo fill that field with Left 4 digits of ConsignmentNo, and then we just change in our all coding "ExportDocs" with "ConsignmentYear" so that we may get in our report all Consignments in their respective year.

Is my approach right? or i am on the wrong? Please guide.

In the report "ClientName" is displaying in Descending Order and in query "qryKhalid_DH" ClientCIN has Sort Order Ascending. I tried to add the Control "ClientCIN in report but it does not shows me ClientCIN in Ascending Order and ClientName in Descending Order. My requirement is to display ClientCIN in Ascending Order with their respective ClientName. I am unable to get it resolve.

Could you please be helpful again.
Thanks in advance.
Regards,
Khalid




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

Khalid and John,
 
I just uploaded a crosstab report demo using the same data. The report design allows for a predefined number of columns based only on the horizontal width of the page. If the actual crosstab would generate additional columns, they are automatically "wrapped" below the first set of columns. For instance if the columns were the month January - December and you only had width for 6 columns January - June would display first in a group and July - December would display later. There are realistically no limits to the number of column headings that could be generated with this solution.
 
There is much less code and probably more efficient with larger data sets.
 
It took me a while to review my demo and re-purpose it with Khalid's data. Let me know if you have any questions. 
 
Duane Hookom, MVP
MS Access
 

To: MS_Access_Professionals@yahoogroups.com
From: MS_Access_Professionals@yahoogroups.com
Date: Wed, 18 Feb 2015 16:59:34 +0100
Subject: Re: [MS_AccessPros] Report based on Crosstab query



Khalid-

All you need are the rptKhalidMT report and the ztblKhalidReport table.  You can rename the report and change the report header.  If you want to rename the table, you will have to fix the code behind the report that references the table.  

    ' Clear out the "working" table
    db.Execute "DELETE * FROM ztblKhalidReport", dbFailOnError

and

    ' Open the output recordset
    Set rstO = db.OpenRecordset("ztblKhalidReport", dbOpenDynaset, dbAppendOnly)

And you will have to change the Record Source of the report.

You should copy those two objects into your front end.  Do not modify your existing backend.

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 Feb 18, 2015, at 4:26 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John,
Marvelous!
I un-zipped the file you up-loaded PCTL_be. I did checked/run the report also viewed the query and table.

I'm sure my other tables would be as they were. I would also have to modify report header as per my requirement.

Can i re-name the table before linking & also re-name query and report. I will deeply observe the report's Open event.

Should i over write PCTL_be on my original file confidently?
 
Once again thank you very much John. You always have been great support and help to me.
Thanks to Duane also for being helpful and providing all assistance & help.

Regards,
Khalid



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

https://groups.yahoo.com/neo/groups/MS_Access_Professionals/files/2_AssistanceNeeded/PCTL_be.zip
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 Feb 18, 2015, at 1:39 PM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John,
Congratulations! you got the solution.
But i cannot see any file, detail about table or some other thing. Are you still working on it?
Waiting...

Regards,
Khalid


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

Khalid-

I built a solution that uses a "working" table.  The report prompts you for a year (you could also get the value from an open form), runs the Crosstab filtered for the year, then dumps the result into the working table.  It modifies the captions on the labels to reflect the actual field names from the filtered data.  Note that the sample report is set up to handle up to 10 Consignment Number values.  If there are more than that in a year, it will warn you and display only the first 10.

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 Feb 18, 2015, at 12:41 PM, John Viescas JohnV@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Well, I tried to apply the KB article solution to Khalid's problem, but I ran into an ancient (since 2002) bug when the report tries to apply a sort to the modified Crosstab query.  The error message is "Cannot use the crosstab of a non-fixed column as a subquery."  Here's the old KB article on the error:


It's probably going to require dumping the filtered result into a temp table, which I think is what Duane's solution does.  I may play with it some more and will post again if I get a solution.

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 Feb 18, 2015, at 10:24 AM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Duane,
I have uploaded the file PCTL_be in which you will find all the tables.

I hope this would suffice and you can do your working. Anxious for your achievement.

Regards,
Khalid


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

I fairly certain the solution would work. I would not use the whole unbound KB solution since it is bloated with code and less efficient. I would be will to try create a sample if I had the Clients and CollectionVoucher tables.
 
However, I wonder if a simple multi-column subreport would work. Does a ConsignmentNo link to more than one client? If not, base the main report on the unique ClientCIN only. Then display the ConsignmentNo and Count of CartonNo across then down. Allow the subreport grow.
 
Duane Hookom MVP
MS Access
 

To: MS_Access_Professionals@yahoogroups.com
From: MS_Access_Professionals@yahoogroups.com
Date: Tue, 17 Feb 2015 11:18:55 +0100
Subject: Re: [MS_AccessPros] Report based on Crosstab query



Duane-

I don't think your sample database is going to help Khalid.

Khalid-

You need to do something similar to the technique described in the KB article:


Basically, you create unbound text boxes and companion labels in your report and give them names that can be easily indexed in code like txtBox01, txtBox02, etc. and lbl01, lbl02, etc.  In the Open event of the Report, dynamically create the Record Source SQL adding the filter for the year you want.  Then open the query as a Recordset and use the column names to set the label Caption properties.  When you have more labels / text boxes defined that are returned by the query, hid the extra ones.

In the Format event of the Detail section, grab the fields from the current row and put them in the text boxes in a loop.

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 Feb 17, 2015, at 7:43 AM, khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

__._,_.___

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

.

__,_._,___

Tidak ada komentar:

Posting Komentar