How many records as known total of them(3 CODi)? (1 Viewer)

btamsgn

Member
Local time
Today, 14:09
Joined
Nov 8, 2010
Messages
50
Dear Everyone,
I want to create a sub or function as follows:
- List all materials fields "Manpl" from table "Tnpl" and insert/add into table1.T1,table1.T2,,table1.T3, with condition the same [table1].[tong]
for example: Table1.tong=16.6666666666678(=5.3333333333336+4.6666666666669+6.666666666667 or = 0.6666666666667+ 1.3333333333334+14.6666666666674) from fields table [Tnpl].[CODi]
results found : Table1(T1,T2,T3)= CA CD BE, CA BA RD, BE AH ZA, etc.
Capture.PNG

-Please find the attachment for your ref., thanks.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:09
Joined
May 21, 2018
Messages
8,525
Code:
SELECT table1.t1,
       table1.t2,
       table1.t3,
       [A].[codi] + [b].[codi] + [C].[codi] AS CalcValue
FROM   ((table1
         INNER JOIN tnpl AS A
                 ON table1.t1 = A.manpl)
        INNER JOIN tnpl AS B
                ON table1.t2 = B.manpl)
       INNER JOIN tnpl AS C
               ON table1.t3 = C.manpl;
Query2 Query2

T1T2T3CalcValue
AEBARD
14.6666666666674​
AEBKDS
20.6666666666677​
BKCDRD
16.6666666666675​
CACDBE
16.6666666666675​
 

btamsgn

Member
Local time
Today, 14:09
Joined
Nov 8, 2010
Messages
50
Code:
SELECT table1.t1,
       table1.t2,
       table1.t3,
       [A].[codi] + [b].[codi] + [C].[codi] AS CalcValue
FROM   ((table1
         INNER JOIN tnpl AS A
                 ON table1.t1 = A.manpl)
        INNER JOIN tnpl AS B
                ON table1.t2 = B.manpl)
       INNER JOIN tnpl AS C
               ON table1.t3 = C.manpl;
Query2 Query2

T1T2T3CalcValue
AEBARD
14.6666666666674​
AEBKDS
20.6666666666677​
BKCDRD
16.6666666666675​
CACDBE
16.6666666666675​
Dear MajP,
with total: 16.6666666666678 => results found 8 records, however query from you only 1 record.
TotalT1T2T3Dem
16.66666667​
CACDBE
1​
16.66666667​
CABARD
2​
16.66666667​
AEGDBK
3​
16.66666667​
BKCDRD
4​
16.66666667​
BKRCZA
5​
16.66666667​
BEAHZA
6​
16.66666667​
AHRCFG
7​
16.66666667​
AHWSDS
8​
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:09
Joined
May 21, 2018
Messages
8,525
Are you asking for potential 204 results? First 50 of those.
Query3 Query3

TotalT1T2T3
16.6666666666675​
AEASBE
16.6666666666675​
AEBAHH
16.6666666666675​
AEBEAS
16.6666666666675​
AEGDBK
16.6666666666675​
AEHHBA
16.6666666666675​
AEQARC
16.6666666666675​
AEZAWS
16.6666666666675​
AHASRD
16.6666666666675​
AHBAQA
16.6666666666675​
AHBEZA
16.6666666666675​
AHBKFC
16.6666666666675​
AHCDHH
16.6666666666675​
AHDSWS
16.6666666666675​
AHFCBK
16.6666666666675​
AHFGRC
16.6666666666675​
AHHHCD
16.6666666666675​
AHQABA
16.6666666666675​
AHRCFG
16.6666666666675​
AHRDAS
16.6666666666675​
AHWSDS
16.6666666666675​
AHZABE
16.6666666666675​
ASAEBE
16.6666666666675​
ASAHRD
16.6666666666675​
ASBABK
16.6666666666675​
ASBEAE
16.6666666666675​
ASBKBA
16.6666666666675​
ASCARC
16.6666666666675​
ASCBWS
16.6666666666675​
ASRCCA
16.6666666666675​
ASRDAH
16.6666666666675​
ASWSCB
16.6666666666675​
BAAEHH
16.6666666666675​
BAAHQA
16.6666666666675​
BAASBK
 

btamsgn

Member
Local time
Today, 14:09
Joined
Nov 8, 2010
Messages
50
Are you asking for potential 204 results? First 50 of those.
Query3 Query3

TotalT1T2T3
16.6666666666675​
AEASBE
16.6666666666675​
AEBAHH
16.6666666666675​
AEBEAS
16.6666666666675​
AEGDBK
16.6666666666675​
AEHHBA
16.6666666666675​
AEQARC
16.6666666666675​
AEZAWS
16.6666666666675​
AHASRD
16.6666666666675​
AHBAQA
16.6666666666675​
AHBEZA
16.6666666666675​
AHBKFC
16.6666666666675​
AHCDHH
16.6666666666675​
AHDSWS
16.6666666666675​
AHFCBK
16.6666666666675​
AHFGRC
16.6666666666675​
AHHHCD
16.6666666666675​
AHQABA
16.6666666666675​
AHRCFG
16.6666666666675​
AHRDAS
16.6666666666675​
AHWSDS
16.6666666666675​
AHZABE
16.6666666666675​
ASAEBE
16.6666666666675​
ASAHRD
16.6666666666675​
ASBABK
16.6666666666675​
ASBEAE
16.6666666666675​
ASBKBA
16.6666666666675​
ASCARC
16.6666666666675​
ASCBWS
16.6666666666675​
ASRCCA
16.6666666666675​
ASRDAH
16.6666666666675​
ASWSCB
16.6666666666675​
BAAEHH
16.6666666666675​
BAAHQA
16.6666666666675​
BAASBK
Dear MajP,
How to calculate with query 3 ?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:09
Joined
May 21, 2018
Messages
8,525
Sorry the Attachment did not go through. I did a cartesian join of all possible combinations. So this does every combination, but allows repetition. AE, AS, BE
but also includes
AE, BE, AS
AS, AE, BE
AS, BE,AE
BE,AS, AE
....

If you only want one of those then the query is a little more complex.
 

Attachments

  • MajP_Hmany.accdb
    680 KB · Views: 207

btamsgn

Member
Local time
Today, 14:09
Joined
Nov 8, 2010
Messages
50
Sorry the Attachment did not go through. I did a cartesian join of all possible combinations. So this does every combination, but allows repetition. AE, AS, BE
but also includes
AE, BE, AS
AS, AE, BE
AS, BE,AE
BE,AS, AE
....

If you only want one of those then the query is a little more complex.
My opinion, no repetition
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:09
Joined
May 21, 2018
Messages
8,525
Actually if you do not want repitition change the <> to > in qryAll
Code:
SELECT A.MaNPL AS T1, B.MaNPL AS T2, c.MaNPL AS T3
FROM Tnpl AS A, Tnpl AS B, Tnpl AS c
WHERE (((B.MaNPL)>[a].[manpl]) AND ((c.MaNPL)>[b].[manpl] And (c.MaNPL)>[a].[manpl]))
ORDER BY A.MaNPL, B.MaNPL, c.MaNPL;
 

btamsgn

Member
Local time
Today, 14:09
Joined
Nov 8, 2010
Messages
50
Hi All,
Pls write a sub/function with results about 500 record if found because query making pc stable and stading.
1648433430078.png

Looking forwarding to receiving from you, thanks.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:09
Joined
May 21, 2018
Messages
8,525
That query runs instantaneous without any problems on my computer. There is something wrong with your data base if this simple query does not run. Unless you add tens of thousands more records to the source table. Please provide the real database for review.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:09
Joined
May 7, 2009
Messages
19,230
using function to generate result (into table Output).
see form1.
 

Attachments

  • Hmany.accdb
    560 KB · Views: 214

btamsgn

Member
Local time
Today, 14:09
Joined
Nov 8, 2010
Messages
50
using function to generate result (into table Output).
see form1.
Dear arnelgp,
Currently, I want to open 6 columns in output instead of 3 columns
Pls update and advise, many thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:09
Joined
May 7, 2009
Messages
19,230
when i tried using 6 column, the vba goes on "forever".
when it is done, i have exceeded 2g records in Output table.
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:09
Joined
Sep 21, 2011
Messages
14,238
Dear arnelgp,
Pls convert vba to vba access as follows:
Sub XYZ()
Dim sArr(), res(), sRow&, i&, i2&, i3&, T#, T2#, T3#, Tong#, k&
Const e# = 10 ^ (-12) 'Sai so cho phep
Const n& = 50 ' results rows found

i = Range("B999999").End(xlUp).Row
res = Range("B3:C" & i).Value
sArr = Range("B3:C" & i).Value
Range("B3:C" & i).Value = res
ReDim res(1 To n, 1 To 3)
Tong = Range("F3").Value 'Tong can tìm
sRow = UBound(sArr)

For i = 1 To sRow - 2
T = sArr(i, 2)
If T >= Tong Then Exit For
For i2 = i + 1 To sRow - 1
T2 = T + sArr(i2, 2)
If T2 >= Tong Then Exit For
For i3 = i2 + 1 To sRow
T3 = T2 + sArr(i3, 2)
If T3 > Tong + e Then
Exit For
ElseIf T3 >= Tong - e Then
k = k + 1
res(k, 1) = sArr(i, 1)
res(k, 2) = sArr(i2, 1)
res(k, 3) = sArr(i3, 1)
If k = n Then GoTo Ketqua
End If
Next i3
Next i2
Next i
Ketqua:
Range("G3").Resize(n, 3) = res
End Sub
'note: B3:C is from table "Tnpl"
'Tong is from table output
Looking forwarding to receiving from you.
How about doing some of the work yourself? :(
This site (and others) is here to help people, not just write code for those who come here and demand it. :(
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:09
Joined
May 7, 2009
Messages
19,230
here is for you 6 numbers.
it is slow since there are 6 numbers to permute.
 

Attachments

  • Hmany_6.accdb
    572 KB · Views: 212

btamsgn

Member
Local time
Today, 14:09
Joined
Nov 8, 2010
Messages
50
here is for you 6 numbers.
it is slow since there are 6 numbers to permute.
Dear arnelgp,
I don't know what happened, after click "generate". My pc's stable and standing and I try to wait 10minutes Finally I close the microsoft access.
 

Attachments

  • 1648515352927.png
    1648515352927.png
    28.2 KB · Views: 181
Last edited:

mercystone

Member
Local time
Today, 10:09
Joined
Sep 20, 2021
Messages
108
How about doing some of the work yourself? :(
This site (and others) is here to help people, not just write code for those who come here and demand it. :(
It is so disheartening to go on everywhere discouraging people who want to be assisted as if you know everything. You should learn to shut your mouth. @arnelgp is very experienced and he has helped so many people. Learning is a process for some people especially who are novices to ms access databases. If you don't want to assist people then ignore their posts. I want to thank these people especially @arnelgp and like-minded who devote their time to assist people even and including downloading databases and updating before uploading. God will bless them.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:09
Joined
May 7, 2009
Messages
19,230
i think it is just like that, creating combination of 6 takes time and computing the total of the 6 combination and comparing
it to the first table also takes some time.
 

Attachments

  • Hmany_6.accdb
    572 KB · Views: 190

Users who are viewing this thread

Top Bottom