473,465 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Number Combination

4 New Member
I have a Table (Table01)in Access with one number field name Num (double)
I want a routine to create a new table example Table02 with 2 fields the first
with combinations of the numbers of Table01 and the 2nd field with the sum of the combinations

Example:

Table01
NUM
1
2
3

Table02
Field01 Field02
1 1
2 2
3 3
1,2 3
1,3 4
2,3 5
1,2,3 6

Thanks,
Sotiris

I have find a code in VB but how can I use it in Access mdb file.


1. Dim Table2() As String
2. Dim TmpDou As Double
3. Dim i() As Integer 'hoping you table has less than 32000 elements
4. Dim j As Integer
5. Dim n As Integer
6. Dim k As Long 'this will be for counting the combinations
7. Dim Boo1 As Boolean
8. TmpDou = UBound(Table1) - LBound(Table1) + 1 'The number of elements in table1
9. TmpDou = 2 ^ TmpDou - 1 'the number of combinations excluding the empty one
10. ReDim Table2(1 To TmpDou, 1 To 2) 'this will be our working space
11. ReDim i(1 To TmpDou) 'this will be for counting
12. 'In case your indexes doesnt start at cero:
13.
14. n = 1
15. Do
16. If n > UBound(Table1) - LBound(Table1) + 1 Then Exit Do
17. ReDim i(1 To n)
18. For j = 0 To n - 1
19. i(j + 1) = LBound(Table1) + j
20. Next
21. Do
22. k = k + 1
23. TmpDou = 0
24. For j = 1 To n
25. Table2(k, 1) = Table2(k, 1) & Table1(i(j)) & ", "
26. TmpDou = TmpDou + Table1(i(j))
27. Next
28. Table2(k, 1) = Left(Table2(k, 1), Len(Table2(k, 1)) - 2)
29. Table2(k, 2) = TmpDou
30. i(n) = i(n) + 1
31. If i(n) > UBound(Table1) Then
32. j = n - 1
33. i(n) = UBound(Table1)
34. Do
35. If j = 0 Then
36. Boo1 = True
37. Exit Do
38. End If
39. If i(j) < i(j + 1) - 1 Then
40. i(j) = i(j) + 1
41. i(j + 1) = i(j) + 1
42. Exit Do
43. Else
44. j = j - 1
45. End If
46. Loop
47. End If
48. If Boo1 = True Then
49. n = n + 1
50. Boo1 = False
51. Exit Do
52. End If
53.
54. Loop
55. Loop
Sep 2 '07 #1
1 2014
MMcCarthy
14,534 Recognized Expert Moderator MVP
Although this can be done in theory it is very bad practice. Storing multiple values in one field has no logical purpose in a database. Can you explain why you are trying to do this?
Sep 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: tom | last post by:
Hi, How do I get the serial number of the harddisk in .NET? I want this to be the same number even if the user has reformatted, so I do not want the volume serial number. Thanx, t
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
109
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has...
22
by: MLH | last post by:
If 3 things can be in one of 2 states, the number of possible combinations is equal to 2^3. But if I have 3 things, 2 of which can be in 2 states and the other in 3 states, what's the simplest...
1
by: alex28011969 | last post by:
hi there, i'm a newby in the world of XML but can somebody tell me how to create a tooltip in a XML document that contains a combination of a name & number? i use a combination with Flash and...
0
barbk
by: barbk | last post by:
Hey all, In DB2 v9 is it possible to have an auto generated number field within a primary key that is a combination of multiple fields? For example resv locn sale_no 1234 789...
10
by: csfong33 | last post by:
Hi, I have arrays below: arr1 = { a, b, c} arr2 = {1, 2, 3} arr3 = {x, y, z} I want to get a combination of these array, as below arr_result = { "a1x", "a1y", "a1z", "a2x", "a2y", "a2z",...
5
by: Bails | last post by:
Hi all I have a theory for a lotto system and need help on how to code it. I want to create 1 massive database with EVERY combination of numbers possible in a given lotto system, then remove all...
8
by: theCancerus | last post by:
Hi All, I am not sure if this is the right place to ask this question but i am very sure you may have faced this problem, i have already found some post related to this but not the answer i am...
1
jinalpatel
by: jinalpatel | last post by:
I am dealing with 3 tables. Here is a brief meta data see the attachment for the relationship Conditions: 1)One GrantIndex can have multiple Deliverables 2)one Deliverable is made from...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.