[英]How to debug.print a query result from the query design in VBA /Access
我想通过VBA从访问执行预定义查询并将其打印到调试输出。 查询设计的名称位于名为report的变量中。
我期待它可以用于:
debug.print db.Execute report
但每次vba自动更正它:
debug.print db.Execute; report
如果我理解正确,那;
代表一条新线,因此在我的情况下毫无意义。 但在这两种情况下,无论有没有新线路,我都会收到错误。 我认为简单的问题是,这不是正确的语法。
我可以找到很多关于如何调试打印在VBA中创建为字符串的查询的信息,但是我找不到任何提示如何通过查询设计输出在Access中预定义的查询。
尝试:
'// You need the parentheses because the result has to be evaluated before it can be passed to the .Print() method
Debug.Print db.Execute(result)
要么
Dim myResult As String
myResult = db.Execute(result)
Debug.Print myResult
在VBA中,只要结果未被分配给任何内容,您就可以在不使用括号的情况下将参数传递给过程/方法。
'// Not assigning anything
MyExampleFunction arg1, arg2, arg3
'// assigning the result, which needs to be evaluated before it can be passed to a variable.
MyResult = MyExampleFunction(arg1, arg2, arg3)
以同样的方式,当你调用Debug.Print
它假定db.Execute
和result
实际上是单独的参数(它无法知道你希望result
首先传递给db.Execute
因为你的语法中没有任何内容可以说明那)。 所以你必须使用括号让它知道。
似乎问题是只能用db.Execute
调用更新而不是查询。 使用debug.print
从查询中打印整个表没有很好的解决方案,但是使用RecordSet
是一种可能的方法。
Dim rs As DAO.RecordSet
Set rs = db.OpenRecordset(Bericht)
Do Until rs.EOF = True
Debug.Print rs("Matrikelnummer"), rs("Bewertung"), rs("Termin (Datum)"), rs("Maximale Bewertung"), rs("Bestehensgrenze"), rs("Versuch"), rs("Äquivalenzleistung")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.