D
DanRoy
Using Access 2003 (11.8204.8221) SP3 in XP Pro
I have a table in which I want to capture summary counts from another table.
I can write a select query and use the count function and get the results I
want. In order to write those results to my summary table, though, I need an
Update query, which does not have the Count function available.
SQL of Select query which provides the results I want:
SELECT DISTINCT Count(Dashmaster.[Team Code]) AS [CountOfTeam Code],
IIf(Len([team code])=1,"0" & [team code],[team code]) AS tc,
Dashmaster.[Change Number] AS dash, [dash] & "-" & [tc] AS keyc
FROM Dashmaster
GROUP BY IIf(Len([team code])=1,"0" & [team code],[team code]),
Dashmaster.[Change Number], Dashmaster.[Team Code];
The results i care about from this query are the CntOfTeam Code and keyc,
which is the match value (Key field) in the Measurement_Plan table.
Not finding a solution there, I went to trying to write SQL in VB.
snippit of code (not complete)
Set rst = db.OpenRecordset("measurement_plan", dbOpenTable, dbConsistent)
DoCmd.SetWarnings False
CurrentDb.Execute "Delete * from Measurement_Plan;", dbFailOnError
DoCmd.OpenQuery "MP_Unique_Team-IPT_Append"
'establishes the shell to which updates are applied
' step through Measurement_Plan 1 record at a time,, collect all inputs
from Dashmaster on match and increment Cnt CAM Boe's field with each match,
then move on to next record in Measurement_plan and repeat
With rst
rst.MoveFirst
'rst.Edit
With CurrentDb.OpenRecordset("dashmaster", dbOpenDynaset)
Do Until .EOF ' To step through all records
If (Len(.Fields("Team code")) = 1) Then TeamRef = "0" &
..Fields("TEAM code") _
Else TeamRef = .Fields("TEAM code")
DashSOW = .Fields("change number") & "-" & TeamRef
SQL = "Update Measurement_Plan " & _
" Set [measurement_plan].[Cnt RAM Boe's] = " & rst![Cnt RAM
Boe's] + 1 & _
" Where [measurement_plan].Key = '" & DashSOW & "'"
Me.Repaint
SQLAll = SQLAll & vbCrLf & DashSOW & " " & rst![Cnt RAM Boe's]
Label30.Caption = SQLAll
CurrentDb.Execute SQL, dbFailOnError
.MoveNext
Loop
' .Update
End With
rst.MoveNext
End With
This got me closer, in that I was able to get results to write to my summary
table, Measurement_Plan, but the results were not correct. The intent in the
code was to query the measurement_Plan table one record at a time and extract
the MATCH value for DashSOW that I needed to find in the details, table,
Dashmaster. If a match, I wanted to increment the counter in the
Measurement_Plan table, the Cnt CAM BOE's field. I did not find a way to
directly calculate a count of occurrence in the dashmaster table to update
the Measurement_Plan table with, though that would be the preferred approach.
Can anyone tell me why this is not working as I expect it should? Can anyone
offer an alternative I have not yet considered?
Thanks
I have a table in which I want to capture summary counts from another table.
I can write a select query and use the count function and get the results I
want. In order to write those results to my summary table, though, I need an
Update query, which does not have the Count function available.
SQL of Select query which provides the results I want:
SELECT DISTINCT Count(Dashmaster.[Team Code]) AS [CountOfTeam Code],
IIf(Len([team code])=1,"0" & [team code],[team code]) AS tc,
Dashmaster.[Change Number] AS dash, [dash] & "-" & [tc] AS keyc
FROM Dashmaster
GROUP BY IIf(Len([team code])=1,"0" & [team code],[team code]),
Dashmaster.[Change Number], Dashmaster.[Team Code];
The results i care about from this query are the CntOfTeam Code and keyc,
which is the match value (Key field) in the Measurement_Plan table.
Not finding a solution there, I went to trying to write SQL in VB.
snippit of code (not complete)
Set rst = db.OpenRecordset("measurement_plan", dbOpenTable, dbConsistent)
DoCmd.SetWarnings False
CurrentDb.Execute "Delete * from Measurement_Plan;", dbFailOnError
DoCmd.OpenQuery "MP_Unique_Team-IPT_Append"
'establishes the shell to which updates are applied
' step through Measurement_Plan 1 record at a time,, collect all inputs
from Dashmaster on match and increment Cnt CAM Boe's field with each match,
then move on to next record in Measurement_plan and repeat
With rst
rst.MoveFirst
'rst.Edit
With CurrentDb.OpenRecordset("dashmaster", dbOpenDynaset)
Do Until .EOF ' To step through all records
If (Len(.Fields("Team code")) = 1) Then TeamRef = "0" &
..Fields("TEAM code") _
Else TeamRef = .Fields("TEAM code")
DashSOW = .Fields("change number") & "-" & TeamRef
SQL = "Update Measurement_Plan " & _
" Set [measurement_plan].[Cnt RAM Boe's] = " & rst![Cnt RAM
Boe's] + 1 & _
" Where [measurement_plan].Key = '" & DashSOW & "'"
Me.Repaint
SQLAll = SQLAll & vbCrLf & DashSOW & " " & rst![Cnt RAM Boe's]
Label30.Caption = SQLAll
CurrentDb.Execute SQL, dbFailOnError
.MoveNext
Loop
' .Update
End With
rst.MoveNext
End With
This got me closer, in that I was able to get results to write to my summary
table, Measurement_Plan, but the results were not correct. The intent in the
code was to query the measurement_Plan table one record at a time and extract
the MATCH value for DashSOW that I needed to find in the details, table,
Dashmaster. If a match, I wanted to increment the counter in the
Measurement_Plan table, the Cnt CAM BOE's field. I did not find a way to
directly calculate a count of occurrence in the dashmaster table to update
the Measurement_Plan table with, though that would be the preferred approach.
Can anyone tell me why this is not working as I expect it should? Can anyone
offer an alternative I have not yet considered?
Thanks