I've looked through the forums and know this question has been asked before, but even after trying what has been suggested I still can't get this to work. I'm fairly new to both VBA and SQL so that could explain why I'm struggling.
我已经浏览了论坛,并且知道之前已经问过这个问题,但即使在尝试了所提出的建议后,我仍然无法让这个工作。我对VBA和SQL都很陌生,这可以解释为什么我在努力。
What I'm trying to do is create a Form that when executed runs this query:
我要做的是创建一个Form,在执行时运行此查询:
strSQL = "SELECT new.[Service Name], new.WBS, new.[Billing Code], new.[CPU Units], new.[VCPU Units], new.[Billing Status], new.[Bill To] " & _
" FROM " & strNew & " AS new LEFT JOIN " & strOld & " AS old ON new.[Service Name] = old.[Service Name] " & _
" WHERE old.[Service Name] Is Null;"
I created the form and have stored the user inputs into both strNew and strOld respectively. However when I execute this code, I receive an error. I've confirmed the values inputted into the form are actual "tables" that are located in the database. Why does this not work? I appreciate the help.
我创建了表单并将用户输入分别存储到strNew和strOld中。但是,当我执行此代码时,我收到一个错误。我已经确认输入到表单中的值是位于数据库中的实际“表”。为什么这不起作用?我很感激帮助。
1 个解决方案
#1
1
I think you are trying to create a dynamic query, the first advise i can give you, you need to read this Erland Sommarskog's article. In order to solve your problem is:
我想你正在尝试创建一个动态查询,我可以给你的第一个建议,你需要阅读这篇Erland Sommarskog的文章。为了解决你的问题是:
Dim strNew As String
Dim strOld As String
strSQL = "SELECT new.[Service Name], new.WBS, new.[Billing Code], new.[CPU Units], new.[VCPU Units], new.[Billing Status], new.[Bill To]" & _
"FROM " & strNew & " AS new LEFT JOIN " & strOld & " AS old ON new.[Service Name] = old.[Service Name]" & _
"WHERE old.[Service Name] Is Null;"
Let us know if this code works for you.
如果此代码适合您,请告诉我们。
#1
1
I think you are trying to create a dynamic query, the first advise i can give you, you need to read this Erland Sommarskog's article. In order to solve your problem is:
我想你正在尝试创建一个动态查询,我可以给你的第一个建议,你需要阅读这篇Erland Sommarskog的文章。为了解决你的问题是:
Dim strNew As String
Dim strOld As String
strSQL = "SELECT new.[Service Name], new.WBS, new.[Billing Code], new.[CPU Units], new.[VCPU Units], new.[Billing Status], new.[Bill To]" & _
"FROM " & strNew & " AS new LEFT JOIN " & strOld & " AS old ON new.[Service Name] = old.[Service Name]" & _
"WHERE old.[Service Name] Is Null;"
Let us know if this code works for you.
如果此代码适合您,请告诉我们。