简体   繁体   English

其中的MSAccess VBA

[英]where msaccess vba

why the following msaccess vba statement fails when add the where statement? 为什么在添加where语句时以下msaccess vba语句失败? I want to check if the field has value 我想检查该字段是否有价值

Set rsMySet = CurrentDb.OpenRecordset("PivotTblInvDepts")

'Start the count at the position number of the first column-oriented field
'Remember that Recordsets start at 0
    For i = 3 To rsMySet.Fields.Count - 1
'*********************************************************************************************************************
'Use the recordset field.name property to build out the SQL string for the current field
    strSQL = "INSERT INTO TabularDepts ([Depts], [Code], [Description], [Qty])" & _
    "SELECT" & "'" & rsMySet.Fields(i).Name & "'" & " AS Dept," & _
    "[PivotTblInvDepts].[Code],[PivotTblInvDepts].[Description]," & _
    "[" & rsMySet.Fields(i).Name & "]" & _
    "FROM PivotTblInvDepts;" & _
    "WHERE" & " (rsMySet.Fields(i).Name)>0"

Try removing the ; 尝试删除; in FROM PivotTblInvDepts; FROM PivotTblInvDepts; .

Also you need space at the end of the previous line. 您还需要在上一行的末尾留出空间。 "[" & rsMySet.Fields(i).Name & "]" & _ should be "[" & rsMySet.Fields(i).Name & "] " & _ . "[" & rsMySet.Fields(i).Name & "]" & _应为"[" & rsMySet.Fields(i).Name & "] " & _ Likewise, make sure to add a space 同样,请确保添加一个空格 so that you do no result in FROM PivotTblInvDeptsWHERE 这样您就不会在FROM PivotTblInvDeptsWHERE产生任何结果

Your current SQL reads something like this 您当前的SQL读取如下内容

INSERT INTO TabularDepts ([Depts], [Code], [Description], [Qty])
SELECT '<data>' As Dept,
[PivotTblInvDepts].[Code],[PivotTblInvDepts].[Description],
[<data>]
FROM PivotTblInvDepts;
WHERE <condition>

After removing the ; 删除后; , the insert will be cleaner. ,插入物会更清洁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM