S
Stephen Cox
am working on a database where there is a requirement to identify specific
sequences of data and then count the instances of a specific sequence and
thereafter write that data to a table.
A typical example of the data being analysed is :
Date Team Result
24/10/2001 A L
28/10/2001 A L
31/10/2001 A W
01/12/2001 B D
02/12/2001 A L
03/12/2001 B D
In this instance Team A has a sequence of 2 L s which is then broken by a
W. Ideally the data that would be written to a separate table would be as
follows:
Date From Date To Team ResultType No of Sequential
Results
24/10/2001 28/10/2001 A L 2
31/10/2001 31/10/2001 A W 1
01/12/2001 03/12/2001 B D 2
I am trying to write a VBA Sub procedure to analyse the data and carry out
this process. The procedure is based upon Do Until Loops but is not working.
I am unable / do not know how to (1) finish the loop so that the first date
when the sequence is broken is returned as the Date To and (2) Subsequently
count and sum the instances contained in any sequence of results.
Can anybody help at all? Any assistance would be much appreciated.
Code so far is as follows:
Public Sub ResultSequence
Set dbs = CurrentDb
Set rst1 = CurrentDb.OpenRecordset("ExtractDataforSequentialResultAnalysis")
firststart = rst1.[Date]
firsttype = rst1.[AwayResult]
rst1.MoveNext
counter = 1
'MsgBox firststart
'MsgBox firsttype
Do Until rst1.EOF
If firsttype <> rst1.[AwayResult] Then
'write to table
writesequence rst1.[Date], rst1.[Away Team], rst1.[AwayResult],
counter
End If
rst1.MoveNext
Loop
End Sub
Sub writesequence(sfrom, team, resulttype, results)
Set addtotable = CurrentDb.OpenRecordset("ResultSequences")
With addtotable
..AddNew
![SequenceFrom] = sfrom
'![SequenceTo] = sto
![team] = team
![SequenceType] = resulttype
![NoOfResults] = results
..Update
End With
End Sub
sequences of data and then count the instances of a specific sequence and
thereafter write that data to a table.
A typical example of the data being analysed is :
Date Team Result
24/10/2001 A L
28/10/2001 A L
31/10/2001 A W
01/12/2001 B D
02/12/2001 A L
03/12/2001 B D
In this instance Team A has a sequence of 2 L s which is then broken by a
W. Ideally the data that would be written to a separate table would be as
follows:
Date From Date To Team ResultType No of Sequential
Results
24/10/2001 28/10/2001 A L 2
31/10/2001 31/10/2001 A W 1
01/12/2001 03/12/2001 B D 2
I am trying to write a VBA Sub procedure to analyse the data and carry out
this process. The procedure is based upon Do Until Loops but is not working.
I am unable / do not know how to (1) finish the loop so that the first date
when the sequence is broken is returned as the Date To and (2) Subsequently
count and sum the instances contained in any sequence of results.
Can anybody help at all? Any assistance would be much appreciated.
Code so far is as follows:
Public Sub ResultSequence
Set dbs = CurrentDb
Set rst1 = CurrentDb.OpenRecordset("ExtractDataforSequentialResultAnalysis")
firststart = rst1.[Date]
firsttype = rst1.[AwayResult]
rst1.MoveNext
counter = 1
'MsgBox firststart
'MsgBox firsttype
Do Until rst1.EOF
If firsttype <> rst1.[AwayResult] Then
'write to table
writesequence rst1.[Date], rst1.[Away Team], rst1.[AwayResult],
counter
End If
rst1.MoveNext
Loop
End Sub
Sub writesequence(sfrom, team, resulttype, results)
Set addtotable = CurrentDb.OpenRecordset("ResultSequences")
With addtotable
..AddNew
![SequenceFrom] = sfrom
'![SequenceTo] = sto
![team] = team
![SequenceType] = resulttype
![NoOfResults] = results
..Update
End With
End Sub