需要VBA帮助的动态SQL [英] Dynamic SQL with VBA help needed
问题描述
大家好,我已经找了一个多星期,找到了一个好的开始,但似乎无法做出我想要的工作。我得到一个错误或一张空白表。
我正在寻找什么。我必须制作一个名为工作的新表。基于另一个名为source的表。我必须每周做一次,但我的来源表格根据周而变化。所以我创建了一个Ref_data其中field1是我的源的表名。和field2是我的source中的列名。
这是我正在开始的已保存查询的示例。
Hello All, I''ve been searching for over a week and have found a good start but can''t seem to make what I want work. I either get an error or a blank table.
What I''m looking for. I have to make a new table called "working" based on another table called "source". I have to do this about once a week but my "source" table changes depending on the week. So I created a "Ref_data" where field1 is the table name of my "source" and field2 are the column names from my "source".
Here is an example of saved query that I''m starting from.
推荐答案
在你的第一段代码中,如果你放置了什么:
In your first block of code, what do you get if you place :
与第19行完全一致地打印SQL3行。
its printing the SQL3 line exactly as it is in line 19.
你的陈述
" PS。在我看来,您每次都需要访问数组的单个元素。在一个循环中。您似乎试图一次性将整个数组传递给SQL。不好。
是的..我在原始帖子的第二次代码尝试中尝试了这个(或者至少我以为我试过这个)。
我以为我应该将记录集添加到数组中,但我在网上找到的所有内容都说记录集几乎是一个数组。我输了的另一个原因。我不认为我理解记录集的一切。哪个没有帮助。
your statement of
"PS. It seems to me that you need to access an individual element of your array each time. Within a loop. You seem to be trying to pass the whole array into the SQL in one go. Not good. "
Yeah.. I attempted this (or at least I thought I attempted this) in the second attempt of code on my orginal post.
I was thinking that I should add the the recordset to an array but everything I was finding online said the recordset is pretty much an array. Another reason I''m lost. I dont think i understand everything about a recordset just yet. Which isn''t helping.
这篇关于需要VBA帮助的动态SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!