我正在尝试遍历一个现有的表(tblSalesOrder),我需要遍历每一行(它们与特定客户相关的地方),并将每一行写入一条SQL语句并执行它。
执行此过程的最简单方法是什么?
在通过SQL将数据写入QuickBooks数据库之前,需要计算行数。
我可以使用下面的代码在php中编写类似的代码,但我不确定如何将其转换为VBA友好的格式:
$sql_count = "SELECT count(*) FROM tblSalesOrder WHERE Customer='cust_number'";
execute_query($sql_count)当上面的值大于0时,vba代码应该遍历查询。
发布于 2014-06-03 11:23:32
您需要一个记录集来执行和存储查询结果。
Dim sql_count As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset您需要连接到数据库连接。"cn“存储到QuickBooks的连接。
sql_count = "SELECT count(*) FROM tblSalesOrder WHERE Customer='cust_number'"
Set rs = cn.Execute(sql_count)
Do While rs.Fields(0).Value > 0 ' rs.Fields(0) should get you the count(*)
' your codes
Loop对于QuickBooks的连接字符串,您可能可以阅读here
发布于 2014-06-04 20:59:05
请参考以下链接。您可以打开记录集:
http://www.qodbc.com/qodbcvisualbasic.htm
http://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/28/57/example-code-of-update-qb-from-ms-access
https://stackoverflow.com/questions/24006469
复制相似问题