【发布时间】:2018-04-09 16:31:19
【问题描述】:
AmeriFood(i), SpanFood(i), IndiFood(i) 的值在导出到我的 Access 表时没有更新。相反,它在整个循环中每次都连续输入值的第一个实例。
InsertIntoString = "INSERT INTO [Data] ([American], [Spanish], [Indian]) "
''''ValuesString = "VALUES ([" & AmerFood(i) & "], [" & SpanFood(i) & "], [" & IndiFood(i) & "])" ' I couldnt get this to work beauce there are spaces in the string.
ValuesString = "VALUES (?,?,?)"
strSql = InsertIntoString & ValuesString
With cmd
Set .ActiveConnection = cn
.CommandText = strSql
.Parameters.Append .CreateParameter(, adVariant, adParamInput, , AmerFood(i))
.Parameters.Append .CreateParameter(, adVariant, adParamInput, , SpanFood(i))
.Parameters.Append .CreateParameter(, adVariant, adParamInput, , IndiFood(i))
.Execute
End With
知道如何让值AmeriFood(i), SpanFood(i), IndiFood(i) 每次在 VBA 代码中循环时更新吗?我单步执行了代码,每个值都更新为正确的文本/值,但它永远不会导出为更新的值,只是给出的第一个值。
我原本打算使用注释掉的行
ValuesString = "VALUES ([" & AmerFood(i) & "], [" & SpanFood(i) & "], [" & IndiFood(i) & "])"
但由于变量字符串中有空格而出错。
我做这件事的方式对我没有影响,我只需要一些工作。
【问题讨论】:
标签: vba excel ms-access export