Hi, I have a textbox in which I enter a Person Pay ID, I want to try and auto
populate several other textboxes with Name and Workplace, I understand I need
to use a DLookup, but unsure on how it works
You can use DLookup, or you can open a Recordset to get the data. Use the AfterUPdate event of the textbox:
Sub YourTextbox_AfterUpdate()
Dim rst As DAO.REcordset
Set rst = Currentdb.OpenRecordset("SELECT * FROM YourPersonTable WHERE PersonIDFIeld=" & Me.YourTextbox)
If Not(rst.EOF and rst.BOF) Then
'/now populate the textboxes
Me.txtName = rst("sName")
Me.txtWorkplace = rst("sWorkPlace")
End IF
Set rst = Nothing
End Sub
There are some potential issues with this, however. If the form is bound, then realize that doing this ANYTIME the ID is
updated will also update the underlying table data ... this is probably what you want to do anyway, but just be aware of
what's going on.
Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com