The query defined as strSQL works perfectly as a standalone list. When implemented into this sub, the code returns error 3061 (too few arguments) on "CallCurrentdb.Execute"
A previous implementation of this code gave me this error, but was resolved by treating a mishandling of quotations and spacing.I fear I am missing a syntax error, or this subquery using the Concat function simply can not be used in this fashion.
Expand|Select|Wrap|Line Numbers
- Private Sub cmdPartTypes_DblClick(Cancel As Integer)
- Dim db As DAO.Database
- Dim rst As DAO.Recordset
- Dim strSQL As String
- strSQL = _
- "SELECT x.CompID, Max(Concat(Nz(x.CompID), Nz(x.PartType))) AS Types " & _
- "FROM (SELECT [Data - Inventory].ID AS [CompID], [Component Library].Type AS [PartType] " & _
- "FROM [Component Library] INNER JOIN [Data - Inventory] ON [Data - Inventory].Description LIKE '*' & [Component Library].Keyword & '*'" & _
- ") AS x GROUP BY x.CompID;"
- Set db = CurrentDb()
- Set rst = db.OpenRecordset(strSQL)
- With rst
- If Not (.BOF And .EOF) Then
- Call .MoveFirst
- Do While Not .EOF
- strSQL = _
- "UPDATE [Data - Inventory] " & _
- "SET [Type] = " & !Types & _
- " WHERE [Data - Inventory].ID = " & !CompID
- Call CurrentDb.Execute(Query:=strSQL)
- Call .MoveNext
- Loop
- End If
- Call .Close
- End With
- Set rst = Nothing
- Set db = Nothing
- End Sub
Here is the Concat function, found in an older post on this site.
Expand|Select|Wrap|Line Numbers
- 'Concat Returns lists of items which are within a grouped field
- Public Function Concat(strGroup As String, _
- strItem As String) As String
- Static strLastGroup As String
- Static strItems As String
- If strGroup = strLastGroup Then
- strItems = strItems & ", " & strItem
- Else
- strLastGroup = strGroup
- strItems = strItem
- End If
- Concat = strItems
- End Function
See this older post for sample tables
Any suggestions are greatly appreciated.