Hi Allen
I started off down that track. I have a record that records monthly
totals
for 5 years - hence the 60 fields, and daily records that record up to
42
daily records. When I started I built it as a single record for each
day/person/project combination. The monthly screen had 42 subforms to
cater
for the days (6 weeks so that I could present it as a calendar and
start
on
the appropriate day on the top row, then end on the fourth or fifth
row).
Problem was it was taking about 30 seconds to load all the queries. My
solution was to go back to a single record for each person/project
combination for the month with 42 allocation fields, and a single
record
for
each person/project for 5 years with 60 fields. Breaks all
normalisation
rules but even after fiddling with indexes I could not get a form with
42
subforms to load successfully.
Since I posted, I have been working on running the first SQL using VB
and
taking the field names to populate the controlsource of the report. It
is
partially working and I think I can get it to run eventually but still
curious as to whether there is an SQL solution.
This is the code at present
Private Sub Report_Open(Cancel As Integer)
subInitialize
strSQL = "SELECT tblPeriod.StartDate, tblPeriod.EndDate,
tblPeriod.Name,
tblPeriod.AllocatedNo" & _
" FROM tblPeriod" & _
" WHERE (((tblPeriod.StartDate)>= #" &
[Forms]![frmResourceReportSelector]![cmbFrom] & "#) AND" & _
" ((tblPeriod.EndDate) <= #" &
[Forms]![frmResourceReportSelector]![cmbTo] & "#));"
RunSelectQuery (strSQL)
rst.MoveLast
intRecs = rst.RecordCount
rst.MoveFirst
For intCounter = 1 To intRecs
strTextBox = "txt" & intCounter
strLabel = "lbl" & intCounter
Me.Controls(strTextBox).ControlSource = rst![AllocatedNo]
Me.Controls(strTextBox).BorderStyle = 1
Me.Controls(strLabel).Caption = rst![Name]
rst.MoveNext
Next
End Sub
Sub subInitialize()
For intCounter = 1 To 12
strTextBox = "txt" & intCounter
strLabel = "lbl" & intCounter
Me.Controls(strTextBox).ControlSource = ""
Me.Controls(strTextBox).BorderStyle = 0
Me.Controls(strLabel).Caption = ""
Next
End Sub
Still to be refined but it does work.
:
Neville, whenevery you have repeating fields (such as P1, P2, ...) it
always
means that you have built a spreadsheet and not a database.
In a relational database, these many fields should be many *records*
in a
related table. This table will have fields like this:
ResourceID indicates which resource this is for.
PeriodID contains the value "P1", or "P2", etc.
Amount the amount for this resource in this period.
So, there will be 60 records for resource 5 if it has data for 60
periods.
With that structure, you can easily query as you requested. Since all
the
amounts are in one column, the question of how to know what field to
look
in
just disappeared.
Form more information, read about "normalization." Here's a starting
point:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html#DatabaseDesign101
I have two tables.
The first is tblPeriod which lists months including start and end
dates.
It
also has an AllocatedNo field which gives every month a number such
as
P1,
P2, P3 etc.
The second is tblResourceXMonth which lists resources assigned to
each
month. It has (amongst other fields) 60 fields called P1 to P60
I want to run a report to look at all assignments between 2 dates.
I
can
select the date range from the tblPeriod and through a query, find I
need
to
look at P1 to P6 for example.
Question is how do I use the fact I know which P fields from the
second
query I want to look at, to get the values of those fields? I can
probably
use VBA to loop through the records but wondered if I can do it
through
SQL.