473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Update Concatenation query using VBA

The following code is intended to update a comma delimited list of all matches in [Data - Inventory].Description using a keyword list from [Component Library].

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
  1. Private Sub cmdPartTypes_DblClick(Cancel As Integer)
  2.  
  3.     Dim db As DAO.Database
  4.     Dim rst As DAO.Recordset
  5.     Dim strSQL As String
  6.  
  7.     strSQL = _
  8. "SELECT x.CompID, Max(Concat(Nz(x.CompID), Nz(x.PartType))) AS Types " & _
  9. "FROM (SELECT [Data - Inventory].ID AS [CompID], [Component Library].Type AS [PartType] " & _
  10. "FROM [Component Library] INNER JOIN [Data - Inventory] ON [Data - Inventory].Description LIKE '*' &  [Component Library].Keyword & '*'" & _
  11. ") AS x GROUP BY x.CompID;"
  12.  
  13.     Set db = CurrentDb()
  14.     Set rst = db.OpenRecordset(strSQL)
  15.     With rst
  16.         If Not (.BOF And .EOF) Then
  17.             Call .MoveFirst
  18.             Do While Not .EOF
  19.                 strSQL = _
  20.                     "UPDATE [Data - Inventory] " & _
  21.                     "SET [Type] = " & !Types & _
  22.                     " WHERE [Data - Inventory].ID = " & !CompID
  23.                     Call CurrentDb.Execute(Query:=strSQL)
  24.                 Call .MoveNext
  25.             Loop
  26.         End If
  27.         Call .Close
  28.     End With
  29.     Set rst = Nothing
  30.     Set db = Nothing
  31.  
  32. End Sub
  33.  

Here is the Concat function, found in an older post on this site.
Expand|Select|Wrap|Line Numbers
  1. 'Concat Returns lists of items which are within a grouped field
  2. Public Function Concat(strGroup As String, _
  3.                        strItem As String) As String
  4.     Static strLastGroup As String
  5.     Static strItems As String
  6.  
  7.     If strGroup = strLastGroup Then
  8.         strItems = strItems & ", " & strItem
  9.     Else
  10.         strLastGroup = strGroup
  11.         strItems = strItem
  12.     End If
  13.     Concat = strItems
  14. End Function
  15.  
For clarity, the end goal is to find and concatenate the Part Type associated with each keyword match and update the [Data - Inventory].Type with the results.

See this older post for sample tables
Any suggestions are greatly appreciated.
Jan 21 '19 #1
1 1294
ADezii
8,834 Expert 8TB
If you can Upload a functional subset of the Database, stripped of any sensitive data, I would be happy to have a look at it.
Jan 23 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bdt513 | last post by:
I am trying to extract the values from a query using VBA. Specifically, I want to concatenate all the values of the "rosEmail" field from query "qselRosterEmailList" into one string (strEmails). I...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
4
by: Shane | last post by:
I would like to update Access by using a txtBox. Is it possible to update Access this way? Example: If I selected the txtBox and input a line of text I would like that line of text to be sent...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
4
by: Kannan s | last post by:
Dear Sir, Sub: help requred to build an Update Query using if or iif I am having two tables with the following fields I wish to create a single update query in MS Access Table1: code,...
2
by: midlothian | last post by:
Hello Trying to update a memo field in an update query using the Replace function, and am getting a type conversion error. Here is my parameter: CStr(Replace(CStr(),"$",Chr$(13) & Chr$(10))) ...
2
by: mochatrpl | last post by:
Is there a way to create a Concatenation Query for 2 columns and at the same time, remove the spacing between them? The fields that I am combining are 2 text fields but for some reason there is 15...
1
by: EwanD | last post by:
I am trying to read through and process an Access Query using VBA. I have used the OpenRecordset method with parameters as below OpenRecordset(sSourceRecordset, dbOpenDynaset) Where...
1
by: Master Ken | last post by:
Hi All, I'm very new to C# and ASP and I am asking for some help as I don't really know where to start on this project. Some background info first I run a report each week which outputs data...
7
by: LaMoRt | last post by:
Hi there! Is there any way to find the user who did some transaction of update in query analyser in certain time ? The update was done manually in query analyser and is not through system....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.