vba - How to pull a value from a table in Access and show it in a textbox based on a unique ID displayed in another textbox? - S

I have a textbox in Form2 named txtEID with an Employee ID value that is passed from another form.I al

I have a textbox in Form2 named txtEID with an Employee ID value that is passed from another form.

I also have a sample textbox named txtFullName that should autopopulate the name of a person from table tblEmployees with table field EmployeeName where Form2.txtEID.value is equal to EID of tblEmployees.

I don't know how to autopopulate the textbox.
I tried a ComboBox with this line in its Rowsource property:

SELECT [tblEmployees].[ID], [tblEmployees].[EmployeeName] FROM tblEmployees WHERE [tblEmployees].[EID] = [txtEID]; 

It is showing the desired value (person's name based on EID of txtEID) in the ComboBox but only as a dropdown list.

How can I set the value of the textbox txtFullName to a person's name from the table based on the EID showing in txtEID?
I also don't know how to set it up in the txtFullName Control Source property.

I have a textbox in Form2 named txtEID with an Employee ID value that is passed from another form.

I also have a sample textbox named txtFullName that should autopopulate the name of a person from table tblEmployees with table field EmployeeName where Form2.txtEID.value is equal to EID of tblEmployees.

I don't know how to autopopulate the textbox.
I tried a ComboBox with this line in its Rowsource property:

SELECT [tblEmployees].[ID], [tblEmployees].[EmployeeName] FROM tblEmployees WHERE [tblEmployees].[EID] = [txtEID]; 

It is showing the desired value (person's name based on EID of txtEID) in the ComboBox but only as a dropdown list.

How can I set the value of the textbox txtFullName to a person's name from the table based on the EID showing in txtEID?
I also don't know how to set it up in the txtFullName Control Source property.

Share Improve this question edited Apr 1 at 4:27 CommunityBot 11 silver badge asked Dec 30, 2024 at 6:10 ShielaShiela 7491 gold badge9 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Use DLOOKUP in the Control Source to pull the information.

DLookUp("[Full_Name]","[Table1]","[EID]=" & [txtEID])

I've wrapped it in an IIF statement as it returns an error if the txtEID control on the form is null.

=IIf(IsNull([txtEID]),"",DLookUp("[Full_Name]","[Table1]","[EID]=" & [txtEID]))

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745413533a4626641.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信