C
cliff
I have the following programme.module for generating all possiible
combination of in a group of 3 items and it works like this
Private Sub Command1_Click()
Dim rs As ADODB.Recordset
Dim stocknames() As String
Dim i As Long
Dim j As Long
Dim k As Long
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open "select stockname from stocknames order by stockname", ,
adOpenForwardOnly, adLockReadOnly
i = 0
ReDim stocknames(0)
Do While Not rs.EOF
ReDim Preserve stocknames(i)
stocknames(i) = rs.Fields("stockname")
i = i + 1
rs.MoveNext
Loop
rs.CLOSE
rs.Open "stockpermutations", , adOpenDynamic, adLockOptimistic
For i = 0 To UBound(stocknames) - 2
For j = i + 1 To UBound(stocknames) - 1
For k = j + 1 To UBound(stocknames)
If i <> j And j <> k And i <> k Then
rs.AddNew
rs.Fields("first") = stocknames(i)
rs.Fields("second") = stocknames(j)
rs.Fields("third") = stocknames(k)
rs.Update
End If
Next k
Next j
Next i
rs.CLOSE
End Sub
first second third
12 23 35
12 23 36
12 35 36
23 35 36
but I want my output is something like this
sr 1
first 12
first 23
first 35
sr 2
first 12
first 23
first 36
In words I want autonumber for a each new groups and display values in
one column as sr i.e., autonumber seperate the combinations. Please help me
..]
thanks
clifford
combination of in a group of 3 items and it works like this
Private Sub Command1_Click()
Dim rs As ADODB.Recordset
Dim stocknames() As String
Dim i As Long
Dim j As Long
Dim k As Long
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open "select stockname from stocknames order by stockname", ,
adOpenForwardOnly, adLockReadOnly
i = 0
ReDim stocknames(0)
Do While Not rs.EOF
ReDim Preserve stocknames(i)
stocknames(i) = rs.Fields("stockname")
i = i + 1
rs.MoveNext
Loop
rs.CLOSE
rs.Open "stockpermutations", , adOpenDynamic, adLockOptimistic
For i = 0 To UBound(stocknames) - 2
For j = i + 1 To UBound(stocknames) - 1
For k = j + 1 To UBound(stocknames)
If i <> j And j <> k And i <> k Then
rs.AddNew
rs.Fields("first") = stocknames(i)
rs.Fields("second") = stocknames(j)
rs.Fields("third") = stocknames(k)
rs.Update
End If
Next k
Next j
Next i
rs.CLOSE
End Sub
first second third
12 23 35
12 23 36
12 35 36
23 35 36
but I want my output is something like this
sr 1
first 12
first 23
first 35
sr 2
first 12
first 23
first 36
In words I want autonumber for a each new groups and display values in
one column as sr i.e., autonumber seperate the combinations. Please help me
..]
thanks
clifford