nicks60610
MIS
This is a complete rookie question as I never code in VB, well not much anyway. I have a table with a few columns, and when I query the table, I get about 4 rows of data, one of the columns I have Sum(col1+col2) As Cycles. Now the record "Cycles" I want to loop through each one and add the total of and call it "TotalCycles" and then use that # for something else. What do I need to do next here in my code to get this done, can someone give me some hints, maybe tell me where to look online to learn the logic, etc?
Thanks in advance:
Dim cmdLookupMachines As New ADODB.Command
Dim rsMachinesIdLookup As New ADODB.Recordset
cmdLookupMachines.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};Dbq=""
cmdLookupMachines.CommandText =
"SELECT [Production Data Table].Date,
[Production Data Table].Shift,
[Production Data Table].Line,
Sum(([Pieces]+([Scrap])/2)) AS [Cycles]" & _
" FROM [Production Data Table]" & _
" WHERE ((([Production Data Table].Date) Between Date() And Date()-1)
AND (([Production Data Table].Line)='1A'))" & _
" GROUP BY [Production Data Table].[Date],
[Production Data Table].[Shift],
[Production Data Table].[Line] "
cmdLookupMachines.CommandTimeout = 15
cmdLookupMachines.CommandType = adCmdText
Dim rowsId As Long
Set rsMachinesIdLookup = cmdLookupMachines.Execute(rowsId)
Dim intRecordCount As Integer
intRecordCount = 1
Dim Line As String
Dim TabWareMachine As String
Dim IntCycles As Long
Dim LastCycleUpdate As Date
Dim idReqDataItemOfMachine As String
While (Not rsMachinesIdLookup.EOF)
Line = rsMachinesIdLookup("Line").Value
TabWareMachine = rsMachinesIdLookup("Line").Value
IntCycles = rsMachinesIdLookup("Cycles").Value
rsMachinesIdLookup.MoveFirst
Do Until rsMachinesIdLookup.EOF
IntCycles = IntCycles + rsMachinesIdLookup("Cycles").Value
Loop
Dim TotalCyclesCounted As Single
TotalCyclesCounted = IntCycles + dblCurrentMeter
End
StandardExit:
Exit Sub
Thanks in advance:
Dim cmdLookupMachines As New ADODB.Command
Dim rsMachinesIdLookup As New ADODB.Recordset
cmdLookupMachines.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};Dbq=""
cmdLookupMachines.CommandText =
"SELECT [Production Data Table].Date,
[Production Data Table].Shift,
[Production Data Table].Line,
Sum(([Pieces]+([Scrap])/2)) AS [Cycles]" & _
" FROM [Production Data Table]" & _
" WHERE ((([Production Data Table].Date) Between Date() And Date()-1)
AND (([Production Data Table].Line)='1A'))" & _
" GROUP BY [Production Data Table].[Date],
[Production Data Table].[Shift],
[Production Data Table].[Line] "
cmdLookupMachines.CommandTimeout = 15
cmdLookupMachines.CommandType = adCmdText
Dim rowsId As Long
Set rsMachinesIdLookup = cmdLookupMachines.Execute(rowsId)
Dim intRecordCount As Integer
intRecordCount = 1
Dim Line As String
Dim TabWareMachine As String
Dim IntCycles As Long
Dim LastCycleUpdate As Date
Dim idReqDataItemOfMachine As String
While (Not rsMachinesIdLookup.EOF)
Line = rsMachinesIdLookup("Line").Value
TabWareMachine = rsMachinesIdLookup("Line").Value
IntCycles = rsMachinesIdLookup("Cycles").Value
rsMachinesIdLookup.MoveFirst
Do Until rsMachinesIdLookup.EOF
IntCycles = IntCycles + rsMachinesIdLookup("Cycles").Value
Loop
Dim TotalCyclesCounted As Single
TotalCyclesCounted = IntCycles + dblCurrentMeter
End
StandardExit:
Exit Sub