预期功能/变量错误消息 [英] Expected function / variable error message

查看:37
本文介绍了预期功能/变量错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SQL为我的访问数据库编写一个简单的追加查询.尝试执行代码后,我得到的消息是:

i am trying to write a simple append query using SQL for my access database. Upon trying to execute the code, the message i am getting is:

编译错误.预期的函数或变量

Complilation error. Exepected function or variable

该查询是联接4个表并将字段粘贴到另一个表中的查询.使用标准的MS Access查询时,它可以正常工作.然后,我生成并复制了SQL代码(如下所示),但不幸的是无法使查询正常工作.

The query is a query which joins 4 tables and pastes the fields into another table. When using a standard MS Access query it works fine. I then generated and copied the SQL code (below) but unfortunately cannot get the query to work.

关于奇怪事物的最后注释.与我已经成功编写的所有其他SQL查询不同,在将Application.DoCmd.RunSQL(st_sql)写入VBA之后,由于某种原因,"L"和(st_sql)"之间的空间被截断了.对于整个例程中的其他任何字符串,在我成功进行其他追加查询的情况下,都不会发生.

A final note about something strange. Unlike all the other SQL queries i have successfully written, this one, upon writing the Application.DoCmd.RunSQL (st_sql) into VBA, the space between the "L" and the "(st_sql) for some reason gets truncated.. Strange, this doesnt happen for any other string in the Whole routine where i successfully have other append queries.

下面是代码:

st_sql = "INSERT INTO[tblContactReporting03]([ID Project],[tblProjManagementPhaseHierarchy],[tblProjManagementSubPhaseHierarchy],[ID_Event],[SubTask_Hierarchy],[Project],[Sub project],[Project_Phase],[Project_Sub_Phase],[ContactFullName],[Role_Type],[type],[Event],[Effective_date],[Commitment],[Sub_task_name],[Status],[Notes])" & _
            "SELECT[tblProjectMasterList].[ID Project],[tblProjManagementPhase].[Hierarchy],[tblProjManagementSubPhase].[Hierarchy],[tblContactReporting02].[ID_Event],[tblContactReporting02].[SubTask_Hierarchy],[tblProjectMasterList].[Project],[tblProjectMasterList].[Sub project],[tblProjManagementPhase].[Project_Phase],[tblProjManagementSubPhase].[Project_Sub_Phase],[tblContactReporting02].[ContactFullName],[tblContactReporting02].[Role_Type],[tblContactReporting02].[type]," & _
            "[tblContactReporting02].[Event], [tblContactReporting02].[Effective_date],[tblContactReporting02].[Commitment],[tblContactReporting02].[Sub_task_name],[tblContactReporting02].[Status],[tblContactReporting02].[Notes]" & _
            "FROM[tblProjectMasterListINNER JOIN ([tblProjManagementPhase] INNER JOIN ([tblContactReporting02] INNER JOIN [tblProjManagementSubPhase] ON [tblContactReporting02].[ID_Project_Sub_Phase] = [tblProjManagementSubPhase].[ID_Project_Sub_Phase]) ON ([tblContactReporting02].[ID_Project_Phase] = [tblProjManagementPhase].[ID_Project_Phase]) AND ([tblProjManagementPhase].[ID_Project_Phase] = [tblProjManagementSubPhase].[ID_Project_Phase])) ON [tblProjectMasterList].[ID Project] = [tblProjManagementPhase].[ID_Project]" & _
            "ORDER BY [tblProjectMasterList].[ID Project], [tblProjManagementPhase].[Hierarchy], [tblProjManagementSubPhase].[Hierarchy], [tblContactReporting02].[ID_Event], [tblContactReporting02].[SubTask_Hierarchy];" & _
Application.DoCmd.RunSQL(st_sql)

推荐答案

在运行之前,我建议使用Debug.Print st_sql,以便能够调试构造的SQL.

I'd recommend a Debug.Print st_sql before running so that you'll be able to debug the constructed SQL.

您得到的错误是因为RunSQL是一个子对象,而不是一个函数,因此您需要将其称为1)而不带括号:

The error you're getting is because RunSQL is a sub, not a function, so you need to call it 1) without parentheses:

Application.DoCmd.RunSQL st_sql

或2)在"Call"前面加上括号:

or 2) preceed it with Call and use parentheses:

Call Application.DoCmd.RunSQL(st_sql)

对于不需要使用返回值的函数,可以使用语法2.

You can use syntax 2 for functions that when you don't need to use their return value.

这篇关于预期功能/变量错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆