Know the children of an account in the account tree by vba or query

HASAN-1993

Member
Local time
Today, 21:05
Joined
Jan 22, 2021
Messages
89
Hello all
I want to know the children of an account in the account tree
I have attached a picture on the topic
I have a table and I want to extract from it the children of a specific account. Is there a way through the vba or sql?
Thanx
 

Attachments

  • Untitled1.png
    Untitled1.png
    11.8 KB · Views: 119
Do you really want accounts 1 and 11 if entered value is 1?

If you really only want account 1, maybe something like:

SELECT * FROM table WHERE Left(fieldname, Len([enter parent])=[enter parent];
 
I guess it won't do this
Because the table could be like this
I think this has something to do with recursion
 

Attachments

  • Untitled3.png
    Untitled3.png
    8.9 KB · Views: 115
In addition, it is possible that the father’s account does not include the son’s numbers
The code should go down the ladder step by step
 

Attachments

  • Untitled4.png
    Untitled4.png
    9.3 KB · Views: 125
If you wanted to do this in SQL and it is recursive data, I usually have two additional fields in my table. One to store the Top node and one to store the level. Then I run recursive code to update the node and the level for each record.

Then you can filter on TopNode, and sort by level, and then ID.
 
I was hoping to avoid recursion. Access doesn't handle it well. It is a common topic. Have you searched?

I don't understand table structure. Is there really only one field? How do you order records so as to 'go down the ladder'? My suggestion didn't care about record order. Also don't understand "possible that the father’s account does not include the son’s numbers".

Are you saying 11 is a child of 1?
 
I was hoping to avoid recursion. Access doesn't handle it well. It is a common topic. Have you searched?

I don't understand table structure. Is there really only one field? How do you order records so as to 'go down the ladder'? My suggestion didn't care about record order. Also don't understand "possible that the father’s account does not include the son’s numbers".

Are you saying 11 is a child of 1?
Yes
Because these accounts are called accounting, the qualitative account
It collects accounts from various accounting account trees
 
Last edited:
Yes, my brother
I might be wrong, and now a days you cannot assume anything, but I think June might be a Sister.;)
 
I might be wrong, and now a days you cannot assume anything, but I think June might be a Sister.;)
I did not notice this matter
It was modified before misfortune occurred, which I had not anticipated
 
I might be wrong. In English that is a common female name, but I had to google and learned it used to be a common boy name as well.
 
I had to search that and came up with an Egyptian Proverb
News that's for money today will be for free tomorrow
I assume that means that current information may be valuable today (like financial information) but of little use later.

Anyways, would thread #5 work?
 
I had to search that and came up with an Egyptian Proverb

I assume that means that current information may be valuable today (like financial information) but of little use later.

Anyways, would thread #5 work?
Haha I heard this proverb before and I felt it was right for the confusion we are in
 
Anyway for the solution
What I want exactly is the result that is in the picture.
If it only works on the same table, we will Insert it to another table
But what I want is for the result to be on another table
 
If that is a self refencing table and you can add to the table the two fields "TopAccount" and "Level"

Code:
ID  TopAccount  Level
1       1             1
11      1             2
1001   1             3
1002   1             3

You can first span the table recursively and set the TopAccount and Level for each record. Then Simply

Select ID from SomeTable Where TopAccount = 1 Order by Level, ID

If you have no privileges to the table and can create a Temp table then make a temp table to save the ID, TopAccount, and Level.
 
The top account for the accounts could not be determined
Because it is possible for the user to choose Account 11 and request his children
It is not a requirement that the higher account be specified
In addition, as I said recently, it is possible for the father's account to be completely different from the son's account
So I said we should go down the stairs step by step
As we previously did with recursive sum
 
I would do it the same way. Have a form an pick your Account that you want all the subaccounts for. Span from that node down and set the Level and Parent. Basically you are querying a branch.

If I wanted from 11 down it updates the TopAccount and Level from there.

Code:
ID  TopAccount  Level

11     11             1
1001   11            2
1002   1 1           2

You just have to run the code to update before running your query.
If I get a chance I will demo.
 

Users who are viewing this thread

Back
Top Bottom