EmployeeID is numeric.
EmployeeID is numeric.
Code:Private Sub Command19_Click() Dim rs as DAO.RecordSet dim txtID dim txtName txtID = Forms![LoginForm2]![txtEmployeeID] txtName = Forms![LoginForm2]![Text13] Set rs = CurrentDb.OpenRecordset("SELECT * FROM CoachTable WHERE EmployeeID = " & txtID, dbOpenDynaset) If rs.EOF Then txtName = DLookup("CoachName", "HourlyTable", "EmployeeID= " & txtID) Forms![LoginForm2]![Text13].SetFocus Forms![LoginForm2]![Text13] = txtName Else txtName = DLookup("CoachName", "CoachTable", "EmployeeID= " & txtID) Forms![LoginForm2]![Text13].SetFocus Forms![LoginForm2]![Text13] = txtName End If End Sub
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
Somehow my if statement is always true no matter what. That is why it is not going into the else statement.
OK now we know that EmployeeID is actually a text field, try:
Code:Private Sub Command19_Click() Dim rs as DAO.RecordSet Dim txtID Dim txtName txtID = Forms![LoginForm2]![txtEmployeeID] txtName = Forms![LoginForm2]![Text13] Set rs = CurrentDb.OpenRecordset("SELECT * FROM CoachTable WHERE EmployeeID = '" & txtID & "'", dbOpenDynaset) If rs.EOF Then txtName = DLookup("CoachName", "HourlyTable", "EmployeeID= '" & txtID & "'") Forms![LoginForm2]![Text13].SetFocus Forms![LoginForm2]![Text13] = txtName Else txtName = DLookup("CoachName", "CoachTable", "EmployeeID= '" & txtID & "'") Forms![LoginForm2]![Text13].SetFocus Forms![LoginForm2]![Text13] = txtName End If End Sub
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
That worked. What did you change?
I put the single quote marks back into the code because EmployeeID is actually a text field. If it was a number field (integer, long, single, double) they would not be needed. If EmployeeID had been numeric then you would need to remove the single quotes.
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick