English 中文(简体)
访问 VBA 中更新语句错误
原标题:update statement error in Access VBA

我试图在一张叫做“tbl_Responses”的表格中更新几个栏目,

varX= DLookup("[ID]", tableName, "[supplierNum] = " & supplierNum)
updateFieldsTbl1="column1,column2,column3,column4"
updateValuesTbl1 ="name,lastname, bla bla"
 There is nothing wrong with those 3 variables above.


sqlUp = "UPDATE " & tableName & "(" & updateFieldsTbl1 & ")" & " SET " & "(" & _ updateValuesTbl1 & ") WHERE ID = " & varX
DoCmd.RunSQL sqlUp

It gives an error in UPDATE statement line. Can you please tell what I am doing wrong? Thanks in advance

最佳回答

您的字符串剖析为 :

UPDATE tableName (column1,column2,column3,column4) SET (name,lastname, bla bla) ...

INSERT 格式类似,该格式对 UPDATE 无效,正确的格式是:

UPDATE tableName 
SET column1 =  name ,
    column2 =  lastname ,
    columnN =  valueN
WHERE ID = X

以这种方式构建绳子, 并且应该有效 。

问题回答

这是INSERT的语法 - 更新它的语法

UPDATE Table SET Field1=Value1, Field2=Value2, etc WHERE ...




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签