CluelessRink
May be worth a new post, instead of tagging on to the same one.
In case Bob has gone to bed, and your need is urgent...
If you are selecting from a unbound combo box to apply a filter. For example, "find" Mr Smith or "find" Neil, after you selected the name from the query, use the AfterUpdate event for the field.
Assuming field name for the combo box is NameQry
Code:
Private Sub NameQry()
'Name query returns EmployeeID, a long interger
If Nz(Me.NameQry, 0) > 0 Then
Me.Filter = "EmployeeID = " & Me.NameQry
Me.FilterOn = True
Else
Me.FilterOn = False
End if
End Sub
Now assume EmployeeCode is a text string...
Code:
Private Sub NameQry()
'Name query returns EmployeeCode, a text string
Dim strQ as String
strQ = CHR$(34) ' Double quote character
If Len(Nz(Me.NameQry, 0)) > 0 Then
Me.Filter = "EmployeeCode = " & strQ & Me.NameQry & strQ
Me.FilterOn = True
Else
Me.FilterOn = False
End if
End Sub
Okay, now assume you are working from a bound combo box where the EmployeeID field is tied to the Employee table...
Let say your combo box bound to EmployeeID uses the SQL statement...
[tt]
Select EmployeeID, EmployeeLN, EmployeeFN, EmpPhone from Employee
[/tt]
Okay, a cute trick is to realize that a combo box returns all values in the Select statment - ID, Last and First Name and Phone number. These values are available to you.
So assuming the EmployeeID combo box has been updated, and you want to populate the other fields (usually unbound since you just need EmployeeID and the other fields are accessible)...
For the AfterUpdate field update
Code:
Private Sub EmployeeID_After_Update()
If Nz(Me.EmployeeID, 0) > 0 Then
Me.txtEmpLN = Me.EmployeeID.Column(1)
Me.txtEmpFN = Me.EmployeeID.Column(2)
Me.txtEmpPhone = Me.EmployeeID.Column(3)
End If
End Sub
Here, you can reference the column number in the select statement and assign it as appropriate.
You can NOT / should NOT assign the value back to another field that also is bound to the Employee table and EmployeeID.
Last one.
You can also use DLookUp (as well as DMAX, DCount, etc)
Bob is a master of this syntax. His aforementioned posts deal with this approach.
Back to the Employee info.
For txtEmployeeLN, Control source is set to...[tt]
=DLookUp("[EmployeeLN]", "tblEmployee", "[EmployeeID] = " & EmployeeID)[/tt]
Hope one of these approaches answered your question.
Richard