文本框作为Access中SQL查询的输入 [英] Textbox as Input in an SQL Query in Access

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

问题描述

我正在尝试在Microsoft Access 2010中创建一个涉及员工记录的数据库.我的宏之一涉及运行以下SQL查询:

I am trying to create a database in Microsoft Access 2010 involving records of employees. One of my macros involves running the following SQL query:

SELECT
    *

FROM
    Employees

WHERE
    [First Name] = [Enter First Name]
    AND [Last Name] = [Enter Last Name];

当前运行查询会在2个对话框窗口中弹出,以输入名字和姓氏.这可以按预期工作,但是我想将查询绑定到数据库中某些文本框旁边的按钮,像这样,这样,当我单击蓝色按钮时,它将使用文本框作为名字和姓氏输入来运行查询.如果可以提供帮助,我不想对VBA有所了解,因为我没有任何编码经验.

Currently running the query results in 2 dialog windows popping up to enter the first and last name. This works as intended, but I want to bind the query to a button in my database next to some text boxes, like this, so that when I click on the blue button it runs the query with the text boxes as the first and last name inputs. I'd like to not get too deep into VBA if I can help it, as I haven't had any experience coding in it.

推荐答案

无需代码-如@Nathan_Sav所说-快速搜索将找到您想要的内容(我发现来自子表单的引用主表单"提供了最好的页面顶部- http://access.mvps.org/access/forms/frm0031. htm )

No code needed - as @Nathan_Sav said a - a quick search will find what you're after (I find "reference main form from subform" gives the best page at the top - http://access.mvps.org/access/forms/frm0031.htm )

SELECT *
FROM Employees
WHERE [First Name]=Forms![Form1]![txtFirstName] AND 
      [Last Name]=Forms![Form1]![txtLastName]

txtFirstName& txtLastName是我在Form1上为文本控件指定的名称.

txtFirstName & txtLastName are the names I gave to the text controls on Form1.

您的宏按钮可以打开查询.

Your macro button can then just open the query.

这篇关于文本框作为Access中SQL查询的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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