Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with dlookup

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
US
Hopefully someone can steer me in the right direction. I have a simple form that a user chooses a last name from and then other textboxes populate with that persons information such as first name, employee # etc.. I am using the following in the on change event of the last name field to populate the above stated fieds:

Code:
Me.EmployeeFirstName.Requery
Me.EmployeeFirstName = DLookup("[firstname]", "qryinfotellerdiff")
Me.Region.Requery
Me.Region = DLookup("[corporate region]", "qryinfotellerdiff")
Me.BranchName.Requery
Me.BranchName = DLookup("[dept name]", "qryinfotellerdiff")
Me.Branch_.Requery
Me.Branch_ = DLookup("[dept number]", "qryinfotellerdiff")
Me.EmployeeNumber.Requery
Me.EmployeeNumber = DLookup("[Empl ID]", "qryinfotellerdiff")

Everything is fine unless there are multiple people with the same last name, the "other" boxes are always populated with the first person in the list, I am assuming its because the dlookup is simply displaying the first one it finds. Can someone offer a better solution for me?

Thanks for any help!

Paul
 
Please disregard. I changed the code to the "OnClick" and it gave me the desired results.
 
Generally a combo box is used to select an employee. The combo box is bound to the unique column from the employee table. The combo box row source would include the other columns that are required for populating your text boxes. I'm not sure why all the Requery code.

This is what I would expect:

Code:
Private Sub cboEmployee_AfterUpdate()
[COLOR=#FF0000][highlight #FCE94F]    [s][/s]' Row Source: SELECT [EmployeeID], [LastName], [FirstName], [Title], [Address], [City], [Region], [PostalCode], [Country]
    '             FROM [Employees] ORDER BY [LastName];
    ' Column Count: 9
    ' Column Widths: 0";1";0";0";0";0";0";0";0"
    ' Bound Column: 1 (EmployeeID)
    ' List Width: 1.25"
    ' Columns are numbered beginning with 0 so the LastName is Column(1)[/highlight][/color]    
    Me.txtCity = Me.cboEmployee.Column(5)
    Me.txtFirstName = Me.cboEmployee.Column(2)
    Me.txtLastName = Me.cboEmployee.Column(1)
    Me.txtAddress = Me.cboEmployee.Column(4)
    Me.txtTitle = Me.cboEmployee.Column(3)
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top