Populating Subform Field with changing variable (1 Viewer)

sherlocked

Registered User.
Local time
Today, 12:00
Joined
Sep 22, 2014
Messages
125
Experts,

I am attempting to populate an "EmpName" field in my datasheet view subform based on the code below. What is happening is that the fields are ALL changing to match the employee number of the most recently added row (see attached image).

Is there a way around this? Your assistance is appreciated as always.

Code:
Private Sub EmpNo_AfterUpdate()
Dim varEmpNo As String
Me.txtEmpName = DLookup("[eLName] & ', ' & [eFName]", "tblEmployees", "eEmpID = '" & varEmpNo & "'")
End Sub
 

Attachments

  • Capture.PNG
    Capture.PNG
    5.7 KB · Views: 32

isladogs

MVP / VIP
Local time
Today, 19:00
Joined
Jan 14, 2017
Messages
18,186
Suggest a different approach.
In your subform record source, add a field EmpName and set this as
Code:
EmpName: [ELName] & ", " & [EFName]

Then have your text field txtEmpName bound to EmpName
 

sherlocked

Registered User.
Local time
Today, 12:00
Joined
Sep 22, 2014
Messages
125
As is often the case, the simplest solution eluded me. Thank you for your kind response! This solved my problem with ease. :)
 

isladogs

MVP / VIP
Local time
Today, 19:00
Joined
Jan 14, 2017
Messages
18,186
You're welcome. Sometimes it just needs another pair of eyes.
 

Users who are viewing this thread

Top Bottom