Hi all,
Apologies for the confusing title; I wasn't sure how to explain it succinctly. Here's what I want to do: I have a table with 3 (relevant) fields - Name, Number and ParentNumber, where ParentNumber is a value of Number on another row of the same table, and I want a form to show the values of the Name, Number and name of the parent. In order to do that, I need to join the table to itself to get the Name of the Parentumber from the child row. For example:
I've seen this in various applications for a chart of accounts listing where you might have the following data:
Account Number, Account Name, Parent Number
100, Assets, <null>
110, Cash, 100
200, Liabilities, <null>
210, Accounts Payable, 200
This is simplified and only one child level but there could be many child levels. On the form, I want to display "110, Cash, Assets".
Right now I have a continuous form for data entry/update with text boxes for Number and Name and an unbound combobox for the Parent Name. I want the user to be able to enter a new Account Number, a new Account Name and select the parent (if applicable) from the combobox dropdown. That part works if I make the row source a query against the underlying table. However it doesn't pull back the existing values since it is unbound. If I bind it to the parent number field, it of course shows the parent number, but I want it to show the parent name.
I was hoping it would be along the lines of:
But that didn't work and even if it did, it wouldn't help for new records.
Also - I know there are other, arguably better, ways to design this using a separate join table but I'm curious how to make this work. Any ideas?
-Brian
Apologies for the confusing title; I wasn't sure how to explain it succinctly. Here's what I want to do: I have a table with 3 (relevant) fields - Name, Number and ParentNumber, where ParentNumber is a value of Number on another row of the same table, and I want a form to show the values of the Name, Number and name of the parent. In order to do that, I need to join the table to itself to get the Name of the Parentumber from the child row. For example:
Code:
SELECT c.Name, c.Number, p.Name
FROM MyTable c LEFT JOIN MyTable p
ON c.ParentNumber = p.Number
I've seen this in various applications for a chart of accounts listing where you might have the following data:
Account Number, Account Name, Parent Number
100, Assets, <null>
110, Cash, 100
200, Liabilities, <null>
210, Accounts Payable, 200
This is simplified and only one child level but there could be many child levels. On the form, I want to display "110, Cash, Assets".
Right now I have a continuous form for data entry/update with text boxes for Number and Name and an unbound combobox for the Parent Name. I want the user to be able to enter a new Account Number, a new Account Name and select the parent (if applicable) from the combobox dropdown. That part works if I make the row source a query against the underlying table. However it doesn't pull back the existing values since it is unbound. If I bind it to the parent number field, it of course shows the parent number, but I want it to show the parent name.
I was hoping it would be along the lines of:
Code:
SELECT p.Name
FROM MyTable p
WHERE p.Number = [Forms]![MyForm]![cboParentNumber]
But that didn't work and even if it did, it wouldn't help for new records.
Also - I know there are other, arguably better, ways to design this using a separate join table but I'm curious how to make this work. Any ideas?
-Brian