Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
KDANKWAH
Starting Member
1 Post |
Posted - 2003-06-07 : 14:54:25
|
I have a table that looks like this:Name of table: CategoryTabFields in tabe: 2Fieldnames: Costctr and CategoryThe data in the table looks like this:200500 Office200500 Meetings200500 Agency200500 Revenue Offset200502 Meetings200502 Office200502 Agency200502 TravelMy problem is I want a query on a combo box that will list the costctr NUMBER once IN THE COSTCTR COLUMN list all categories associated with that cost center IN THE CATEGORIES COLUMN.Can someone help!Thank You!K. |
|
GreySky
Starting Member
20 Posts |
Posted - 2003-06-09 : 11:00:39
|
I don't agree with your naming conventions, and I'm not exactly sure how you intend to use this, but I solved it for you. Unfortunately, it's all left-aligned, as apparently this forum doesn't render tabs.You will need to add an AutoNumber as the first field of your table. Call it CategoryTabID.The solution consists of two queries and a function that acts as your RowSourceType.--qryCategoryTabFirstSELECT CategoryTab.Costctr, First(CategoryTab.CategoryTabID) AS FirstCategoryTabIDFROM CategoryTabGROUP BY CategoryTab.Costctr;--qryCategoryTabSELECT CategoryTab.CategoryTabID, CategoryTab.Costctr, CategoryTab.Category, Not IsNull([qryCategoryTabFirst].[FirstCategoryTabID]) AS IsFirstInSetFROM CategoryTab LEFT JOIN qryCategoryTabFirst ON CategoryTab.CategoryTabID = qryCategoryTabFirst.FirstCategoryTabID;On the form I added a combo-box called cboCategory. Here are a few of its properties.RowSourceType: CategoryRowSource (yes, it's not in the list, type it in)ColumnWidths: 0";1";2";0"ColumnsCount: 4ListWidth: 3"And finally, place this function behind your form class object to feed the data to the combo.Private Function CategoryRowSource(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant Static rs As DAO.Recordset Select Case code Case acLBInitialize ' open the recordset Set rs = CurrentDb.OpenRecordset("qryCategoryTab") CategoryRowSource = True Case acLBOpen ' return a unique ID CategoryRowSource = Timer Case acLBGetRowCount ' drag all records across the network and return a valid count rs.MoveLast: rs.MoveFirst CategoryRowSource = rs.RecordCount Case acLBGetColumnCount CategoryRowSource = 4 Case acLBGetColumnWidth ' Get column width Select Case col ' define the width of the columns (ID field is bound) Case 0 CategoryRowSource = 0 Case 1 CategoryRowSource = 1440 Case 2 CategoryRowSource = 2880 Case 3 CategoryRowSource = 0 End Select Case acLBGetValue ' align to this position and return its value rs.AbsolutePosition = row ' only show the first 2nd col value if not the first If col = 1 Then ' ensure is the first of the set If CBool(rs(3)) Then CategoryRowSource = rs(col) Else CategoryRowSource = "" End If Else ' if not the first column, always show data CategoryRowSource = rs(col) End If Case acLBEnd ' close out Set rs = Nothing End SelectEnd Function-------------David Atkins, MCPEdited by - GreySky on 06/09/2003 11:07:47 |
 |
|
GreySky
Starting Member
20 Posts |
Posted - 2003-06-09 : 11:12:39
|
And now you've seen the function method, I'll show you the 'nr special' method.Just use a query. You can combine this into one query, but I usually like breaking these into two.--qryCategoryTabFirst (same as previous)SELECT CategoryTab.Costctr, First(CategoryTab.CategoryTabID) AS FirstCategoryTabIDFROM CategoryTabGROUP BY CategoryTab.Costctr--final query showing resultsSELECT CategoryTab.CategoryTabID, IIf(IsNull([FirstCategoryTabID]),Null,[qryCategoryTabFirst].[Costctr]) AS TheCostCtr, CategoryTab.Category, Not IsNull([qryCategoryTabFirst].[FirstCategoryTabID]) AS IsFirstInSetFROM CategoryTab LEFT JOIN qryCategoryTabFirst ON CategoryTab.CategoryTabID = qryCategoryTabFirst.FirstCategoryTabID----- HehDavid Atkins, MCP |
 |
|
Andy Verity
Starting Member
12 Posts |
Posted - 2003-06-24 : 03:28:11
|
Not quite sure what you are trying to achieve here.If you have a very long list of categories you could end up without seeing the Costctr. How about putting the costctr into a separate combo box.What is the purpose for the combo box, out of curiosity?Andyquote: I have a table that looks like this:Name of table: CategoryTabFields in tabe: 2Fieldnames: Costctr and CategoryThe data in the table looks like this:200500 Office200500 Meetings200500 Agency200500 Revenue Offset200502 Meetings200502 Office200502 Agency200502 TravelMy problem is I want a query on a combo box that will list the costctr NUMBER once IN THE COSTCTR COLUMN list all categories associated with that cost center IN THE CATEGORIES COLUMN.Can someone help!Thank You!K.
|
 |
|
|
|
|
|
|