PC Review


Reply
Thread Tools Rate Thread

display the result

 
 
cliff
Guest
Posts: n/a
 
      1st Mar 2010
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
 
Reply With Quote
 
 
 
 
Daryl S
Guest
Posts: n/a
 
      2nd Mar 2010
Cliff -

If your stockpermutations file has an autonumber field, then you don't need
to change your code in creating the data to get the field populated. If you
don't have an autonumber field there, just add it. Then you just need a
query to display what you want. Say your autonumber field is called asr.
Then your query would look like this:

SELECT asr, "asr" AS RecType, sr from stockpermutations
UNION ALL
Select asr, "First" AS RecType, [First] from stockpermutations
UNION ALL
Select asr, "Second" AS RecType, [Second] from stockpermutations
UNION ALL
Select asr, "Third" AS RecType, [Third] from stockpermutations
ORDER BY sr, RecType;

Note that the order by works only because the autonumber field and the three
field names are alphabetically in order, so use a autonumber fieldname that
starts before "First".

--
Daryl S


"cliff" wrote:

> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
display a qry result in a form, select from the result & write out Brian Beardmore Microsoft Access Forms 0 16th Feb 2009 11:04 PM
DISPLAY A RESULT bookman3 Microsoft Excel Misc 3 20th Oct 2008 12:58 AM
Way to display result at the end of the sub only kathy.aubin@gmail.com Microsoft Excel Programming 2 21st Sep 2006 05:07 PM
total result of query less than 10K an display as 1 result =?Utf-8?B?RG9ubmEuSy4=?= Microsoft Access Queries 2 20th Oct 2005 01:46 PM
Display result as Yes or No Pat Microsoft Excel Worksheet Functions 1 1st Nov 2004 02:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:14 PM.