[英]How do I autofill a form based on the employee ID entered in access?
This is my first database project so please bear with me. 这是我的第一个数据库项目,请耐心等待。
I'm currently trying to design a database where I have to create a form that has to be filled out by different employees when needed. 我目前正在尝试设计一个数据库,在该数据库中,我必须创建一个表单,该表单必须在需要时由不同的员工填写。 The form can be filled out by the same employee more than once.
同一位员工可以多次填写该表格。 I currently have
我目前有
Table 1 - This table has all the details that are entered in the form that directly populate the table. 表1-此表具有在直接填充该表的表单中输入的所有详细信息。
Table 2 - This table has all the employees' names, email and employee ID. 表2-此表包含所有员工的姓名,电子邮件和员工ID。
In my form, I have used a code to automatically fill the employee ID via windows username (The forms are only filled out by company employee and their windows login name is their employee ID). 在我的表单中,我使用了代码通过Windows用户名自动填写员工ID(表格仅由公司员工填写,而他们的Windows登录名是他们的员工ID)。 I want to automatically fill out their name and email by checking the detected employee ID with the corresponding data in Table 2.
我想通过使用表2中的相应数据检查检测到的员工ID来自动填写他们的姓名和电子邮件。
I have already tried using combo boxes (or maybe I'm not using them right) but I do not want a drop down list. 我已经尝试使用组合框(或者也许我没有正确使用它们),但是我不希望出现下拉列表。 I want the detected employee ID to be checked with the corresponding data in Table 2 (which already has employee ID, Name and email)
我希望将检测到的员工ID与表2中的相应数据进行核对(表2中已经包含员工ID,姓名和电子邮件)
Is this possible to do without involving a drop down list? 在不涉及下拉列表的情况下可以做到吗?
Thank you. 谢谢。
You can do it with Recordset like that 你可以用Recordset这样
Sub FindEmployee
Dim RST As DAO.Recordset, EmployeeID As Long
' You said you have code to get ID:
EmployeeID = YourIDFunction()
' Create recordset with query to your Table2
Set RST = CurrentDb.OpenRecordset("SELECT [Name], [Email] " _
& " FROM Table2 WHERE EmployeeID = " & EmployeeID, dbOpenSnapshot)
If RST.RecordCount > 0 Then
' Fill fields on your form with data from recordset:
Me.NameField = RST(0)
Me.EmailField = RST(1)
Else
' Nothing is found
End If
' Close and destroy recordset:
RST.Close
Set RST = Nothing
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.