VBA for Access中的SQL [英] SQL in VBA for Access

查看:62
本文介绍了VBA for Access中的SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个简单的查询,我想在Access中的VBA中执行。我的表单有一个按钮,按钮的click事件中存在以下代码:

Hi All,

I have a simple query that I want to execute in VBA in Access. My form has a button and the following code exists in the click event of the button:

展开 | 选择 | Wrap | 行号

推荐答案

你的表名不能有空格。 SQL以这种方式查看语句:


FROM - 为表做好准备

项目 - 好的,这是我想要的表

**备用其他功能或其中的条款**


信息 - 查找信息功能。 WTF!?!?!?我找不到它。抛出一个错误。


我的建议是将表名更改为Project_Info_Table或其他东西。


希望这有帮助

- LB
Your table name can''t have spaces. SQL looks at the statement this way:

FROM - get ready for a table
Project - ok, this is the table I want
**standby for additional functions or where clause**

Info - look for the info function. WTF!?!?!? I can''t find it. Throw an error.

My advice would be to change the table name to Project_Info_Table or something.

Hope this helps
- LB


您好,更改表名的另一种方法是附上表格方括号中的名称。方括号在sql中用于处理字段和表名称中的空格。

Hi, another alternative to changing your table name is to enclose the table name in square brackets. Square brackets are used in sql to handle spaces in field and table names.

展开 | 选择 < span class =codeDivider> | Wrap | 行号


我更改了表名,并以下列两种方式使用它:


首先:


strSQL =" SELECT * FROM Project_info_Tbl;"

db.Execute strSQL


错误:无法执行SELECT查询


第二名:


strSQL =" SELECT * FROM Project_info_Tbl;" ;

DoCmd.RunSQL strSQL

DoCmd.Close acForm,Me.Name

设置db = Nothing


错误:RunSQL操作需要一个由SQL语句组成的参数
I changed the name of the table and used it in the following 2 ways:

First:

strSQL = "SELECT * FROM Project_info_Tbl;"
db.Execute strSQL

Error: Cannot execute SELECT Query

Second:

strSQL = "SELECT * FROM Project_info_Tbl;"
DoCmd.RunSQL strSQL
DoCmd.Close acForm, Me.Name
Set db = Nothing

Error: A RunSQL action requires an argument consisting of an SQL statement


这篇关于VBA for Access中的SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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