?
Solved

Very complicated report - Need help

Posted on 2012-12-30
11
Medium Priority
?
368 Views
Last Modified: 2013-01-04
I hope I can explain the challenge.  I am trying to write an Access report which has to show 52 rows of data.  But first of all prior to the opening of the report is a form which asks the user to enter the current year.  Example: "2012".  Then going down the report vertically I need to show the week number in the first column.  So I guess I need VBA code to loop 52 times but increment by weeks or 7 days each row.  And then next to the week number I need a text box filled with a complicated formula.  Here is my attempt at explaining the formula...

"Molds" = sum total of ([Qty] from "tblCast" divided by [Patterns_On] from "tblPartsMasters") for that week (week 1, week 2, week 3, etc.) where [Molder] from "tblCast" = "Airset Floor" and [Cust] = "ABCCompany".  [Cust] is from "tblPartsMasters" joined to "tblCast" by the field [PartN] in "tblCast" and [Part_No] in "tblPartMasters".    Both [PartN] and [Part_No] are text fields.

So the final report will look like:

Week     Molds
1               4
2               16
3               23
4               7
etc through 52 weeks.


I suspect this question should be worth much more than 500 points but if anyone can assist I sure will appreciate it.  I actually have to create 13 more text fields like the one I've explained horizontally on the report but if someone can help with this first one I think I can take it from there.

--Steve
0
Comment
Question by:SteveL13
11 Comments
 

Author Comment

by:SteveL13
ID: 38731032
One additional comment:  If the "Molds" answer is "0" then I need a "0" on the report.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 38731039
How do you know what week each record belongs to?
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38731042
This would be much easier if you could provide a copy of the database.  Just remove any private information first.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:SteveL13
ID: 38731045
Peter57r:  Sorry.  By [Date] in "tblCast".
0
 
LVL 40

Expert Comment

by:als315
ID: 38731046
Will be good if you upload DB with some sample data.
You need query as report source. As I've adviced you in previous question, you need table with numbers from 1 to 52 if you like to show all weeks, independently from data for this week exists or not. In first query - calculate week number and group by this number. In other column - calculate Molds. In second query left join table witn numbers (1-52) and your query. If you like to have 0, use nz([Molds],0) for molds column.
You should also take in mind that fist and last week in year may have less then 7 days.
0
 

Author Comment

by:SteveL13
ID: 38731061
Attached... a VERY stripped down sample of the database.
SampleDatabase.zip
0
 
LVL 40

Expert Comment

by:als315
ID: 38731111
May be you need something like this. As I can see you like to have all molders in report. You can use transform query. Check Mold calculation in qryMold. May be logic is wrong.
SampleDatabase.zip
0
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 38731137
Some corrections:
1. Error in week calculation query.
2. You can have more then 52 weeks in a year. For example, last week of 2012 has number 53.
SampleDatabase.zip
0
 

Author Comment

by:SteveL13
ID: 38732661
To als315:

Using your last SampleDatabase can you help me get the total numbers in each total column also?  I'm having trouble figuring out how you did this.

Also, is the form being used to determine which year's data to go after?

Thank you so much for what you've done already.

--Steve
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38732662
Hmm ... the last days of this December belongs to week 2013W01.

And ISO_WeekCount(Date) => 52

Year 2009 and 2015, however, had/will have 53 weeks.

Public Function ISO_WeekCount( _
  ByVal datYear As Date) _
  As Byte

' Calculates number of weeks in year of datYear according to the ISO 8601:1988 standard.
'
' May be freely used and distributed.
' 2001-06-26. Gustav Brock, Cactus Data ApS, CPH

  Dim bytISO_Thursday As Byte

  ' No special error handling.
  On Error Resume Next
  
  bytISO_Thursday = Weekday(vbThursday, vbMonday)
  
  datYear = DateSerial(Year(datYear), 12, 31)
  ' Subtract one week if datYear is in week no. 1 of next year.
  datYear = DateAdd("ww", Weekday(datYear, vbMonday) < bytISO_Thursday, datYear)
  
  ISO_WeekCount = DatePart("ww", datYear, vbMonday, vbFirstFourDays)
  
End Function

Open in new window

/gustav
0
 
LVL 40

Expert Comment

by:als315
ID: 38733260
Steve: what total value you like to use? You have Total in each line and in each column. Can you show expected result?

Form is used to calculate max week number in selected year and limit query to this number.
You should analyze Gustav's comment. May be you had to change week number calculation.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question