Hey everyone,
I have a table that has vendors and managers associated to that vendor. I am trying to create a recordset with an SQL statement that picks the vendors based on manager and then group by. I need this because the table can house the same vendor multiple times. I have it working now, but they display the vendor numerous times based on how many orders are in the table. How do I use the group by method? The below code works without the group by. As soon as I add group by it throws an error (Run time error 3121 - Cannot group on fields selected with '*'.) Here is the code that works with the group by commented out
I can explain the code - vendormanager equals managerName which is a variable DLOOKUP value based on who opened the form. The column that I want to Group By is the vendorname. I have it populating into a list box. Below is the code for the listbox
Any suggestions on how I can get the vendor name to populate once instead of all the times they placed orders? Thanks
I have a table that has vendors and managers associated to that vendor. I am trying to create a recordset with an SQL statement that picks the vendors based on manager and then group by. I need this because the table can house the same vendor multiple times. I have it working now, but they display the vendor numerous times based on how many orders are in the table. How do I use the group by method? The below code works without the group by. As soon as I add group by it throws an error (Run time error 3121 - Cannot group on fields selected with '*'.) Here is the code that works with the group by commented out
Code:
Set db = CurrentDb
strSQL = "SELECT * FROM tablename Where vendormanager = '" & managerName & "';" 'GROUP BY vendorname;"
Set rs = db.OpenRecordset(strSQL)
I can explain the code - vendormanager equals managerName which is a variable DLOOKUP value based on who opened the form. The column that I want to Group By is the vendorname. I have it populating into a list box. Below is the code for the listbox
Code:
Me.lstvendorcounts.RowSource = ""
Do Until rs.EOF
Me.lstvendorcounts.AddItem rs![vendorname]
rs.MoveNext
Loop
Any suggestions on how I can get the vendor name to populate once instead of all the times they placed orders? Thanks