简体   繁体   English

MS Access 2003-基于以前的表单域自动填充表单域。

[英]MS Access 2003 - Auto fill form-field based on previous form field.

I am currently attempting to design a database that requires a number of users inputting data via forms. 我目前正在尝试设计一个数据库,该数据库需要许多用户通过表单输入数据。

one of these tables is a 'user' table. 这些表之一是“用户”表。 Amongst the information in the table is userid (int), username (text), first name (text), last name (text) 表格中的信息包括用户ID(int),用户名(文本),名字(文本),姓氏(文本)

In the even that I'm filling out a form and supply the the username in the username field is it possible if the username already exists to pull the first name and last name from the user table and auto-populate those form fields? 即使我正在填写表单并在用户名字段中提供用户名,如果用户名已经存在,是否有可能从用户表中提取名字和姓氏并自动填充这些表单字段? If so can you point me in the right direction please? 如果可以的话,您能指出我正确的方向吗?

Directly via access functionality or via vba? 直接通过访问功能还是通过vba? If not possible in 2003 is this possible in 2007? 如果在2003年不可能,那么在2007年是否有可能?

I have a similar form and i use to make these field as Comboboxes. 我有一个类似的表格,我使用这些字段作为组合框。 Then set the property row source as a query. 然后将属性行源设置为查询。

Set the criteria Where like this 设置条件像这样

WHERE ((([Users].Username) Like '*' & [Forms]![YourForm]![Username] & '*'));

This will allow the user to choose the name as fast as possible 这将允许用户尽快选择名称

But it will not fill it automatically because my users can have the same username as others. 但是它不会自动填充它,因为我的用户可以使用与其他用户相同的用户名。

Ok now for the auto fill (yes i did find one example), This will fill the username after you filled the userid (Both should be comboboxes in this case called Usernamecombo and useridcombo) First make the query with a SQL similar to this: 现在可以自动填充了(是的,我确实找到了一个示例),在填充用户标识后,这将填充用户名(在这种情况下,两者都应为组合框,分别称为Usernamecombo和useridcombo)。首先使用类似于以下内容的SQL进行查询:

SELECT [User].username FROM User WHERE ((([User].userid) Like '*' & [Forms]![Yourform]![useridcombo] & '*'));

Lets call this query "qry_username". 让我们将此查询称为“ qry_username”。 Then go to designview of the form and to the properties of the useridcombo, in the event/afterupdate property you make a event procedure (VBA) : 然后转到表单的designview和useridcombo的属性,在event / afterupdate属性中创建一个事件过程(VBA):

Private Sub useridcombo_AfterUpdate()

[Forms]![yourform]![Usernamecombo].Value = DFirst("username", "qry_username")
Forms("yourform").[Usernamecombo].Requery 'this last line is optional

End sub

Other fields can be added to the VBA pretty simply(dont forget the query) 其他字段可以很简单地添加到VBA中(不要忘记查询)

Private Sub useridcombo_AfterUpdate()

[Forms]![yourform]![Usernamecombo].Value = DFirst("username", "qry_username")
[Forms]![yourform]![Firstnamecombo].Value = DFirst("Firstname", "qry_username")
[Forms]![yourform]![Lastnamecombo].Value = DFirst("Lastname", "qry_username")
Forms("yourform").[Usernamecombo].Requery 'this last line is optional

End sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MS Access - 打开一个表单,从前一个表单中获取字段值 - MS Access - open a form taking a field value from a previous form 在Access 2003中基于另一个字段将数据获取到一个表单字段中 - Get data into one form field based on another's field in access 2003 根据表单字段中提供的日期查询MS Access中的最新记录 - Query Most Recent Records in MS Access Based on Date Provided in Form Field Access女士根据字段的当前值以连续(表格)形式锁定字段 - Ms Access lock a field based on its current value in continuous (tabular) form MS Access:基于多个表自动填充表单字段 - MS Access: Auto-populate form fields based on multiple tables Ms Ms:如何使用表单中的字段填充表格? - Ms Access: How do I populate a table using a field in a form? 另一个表上的MS Access 2013表单[控制源]查找字段 - MS Access 2013 form [control source] lookup field on another table 使用来自另一个表的数据自动填充Access 2003中的字段 - Auto filling a field in access 2003 with data from another table 用MS Access中另一个字段的值填充一个字段 - Fill a field with the values from another field in MS Access 如何根据另一个条件在Microsoft Access表单中创建必填字段 - How to make a field required in Microsoft Access form based on the criteria of another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM