在Access中创建搜索字段 [英] Creating a search field in Access

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

问题描述

在表单上,​​我希望有一个字段,我可以输入员工的姓氏,点击一个按钮,然后在Employee表中搜索该姓氏。


如果它不存在,则会出现错误弹出窗口。如果确实存在,我希望该员工的姓名出现在我的表格上。


感谢您的帮助。 notsosavy ...

On a form, I would like to have a field that I can enter in an employee''s last name, click on a button, and it would search the Employee table for that last name.

If it doesn''t exist, an error popup would appear. If it did exist, I would like to have that employee''s first and last name appear on my form.

Thanks for your help with this. notsosavy...

推荐答案

您好notso欢迎来到TSDN


[PHP] Private Sub CommandButton_Click()

如果IsNull(textBoxName)= False那么

Me.Recordset.FindFirst" [FeildName] =" &安培; textBoxName

Me!cmbLock = Null

如果Me.Recordset.NoMatch那么

MsgBox"找不到记录",vbOKOnly + vbInformation," ;对不起'

我!textBoxName = Null

结束如果

结束如果

结束子[/ PHP]


此代码需要放在命令按钮的OnClick事件中。它将搜索在文本框中输入的数据。如果没有找到结果,它将显示错误消息,告诉用户未找到记录。 - 对不起你可以把它改成你喜欢的任何东西。一旦执行搜索并显示记录或错误,此代码也将清除输入搜索数据的文本框。
Hello notso and welcome to TSDN

[PHP]Private Sub CommandButton_Click()
If IsNull(textBoxName) = False Then
Me.Recordset.FindFirst "[FeildName]=" & textBoxName
Me!cmbLock = Null
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!textBoxName = Null
End If
End If
End Sub[/PHP]

This code will need to be place in the OnClick event of a command button. It will search for the data entered in a text box. If there is no resulte found it will display an error message telling the user "No Record Found" - "Sorry" you can change this to whatever you like. Once the search is preformed and the record or error is displayed this code will also clear out the text box where the search data is entered.


是的!你给我的是美好的!但是,正如我的名字所示,我是新来访问....我遇到了FieldName的问题。我认为这将是[tblEmployee.LastName],但它不起作用,也没有[tblEmployee!LastName]。所以,我需要再次提供更多信息。抱歉


我在表单的文本框中输入名称Smith,单击命令按钮,代码应该在我的tblEmployee表中查找Smith,用姓氏。我收到运行时错误... 3345 - 未知或无效的字段引用[tblEmployee!LastName]。感谢你的时间......
Yeah! What you have given me is wonderful! However, as my name indicates, I''m new to access....I am having a problem with the FieldName. I thought that this would be [tblEmployee.LastName] but it''s not working, nor [tblEmployee!LastName]. So, I need more info again. sorry

I enter in the name Smith in the textbox in my form, click on the command button, and the code is supposed to look for Smith in my tblEmployee table, by the last name. I am getting runtime errors... 3345 - unknown or invalid field reference "[tblEmployee!LastName]". Appreciate you time...



是的!你给我的是美好的!但是,正如我的名字所示,我是新来访问....我遇到了FieldName的问题。我认为这将是[tblEmployee.LastName],但它不起作用,也没有[tblEmployee!LastName]。所以,我需要再次提供更多信息。抱歉


我在表单的文本框中输入名称Smith,单击命令按钮,代码应该在我的tblEmployee表中查找Smith,用姓氏。我收到运行时错误... 3345 - 未知或无效的字段引用[tblEmployee!LastName]。感谢你的时间......
Yeah! What you have given me is wonderful! However, as my name indicates, I''m new to access....I am having a problem with the FieldName. I thought that this would be [tblEmployee.LastName] but it''s not working, nor [tblEmployee!LastName]. So, I need more info again. sorry

I enter in the name Smith in the textbox in my form, click on the command button, and the code is supposed to look for Smith in my tblEmployee table, by the last name. I am getting runtime errors... 3345 - unknown or invalid field reference "[tblEmployee!LastName]". Appreciate you time...



当然没问题。 FieldName指的是您要搜索的领域。您要搜索的字段的名称是LastName,然后将LastName放在FieldName所在的位置。


还要确保文本框绑定到LastName字段。


Sure no problem at all. The FieldName refers to the the feild in which you are searching for. It the name of the field that you would like to search for is LastName, then put LastName where FieldName is.

Also make sure that your text box is bound to the field LastName.


这篇关于在Access中创建搜索字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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