Hi,
of course you cannot set a field to a value if it already contains a formula for calculation. In this case it needs to be an empty and unbound field. And as this is not a saved field you can use the code above in the Form Current event which occurs on any record change in the main form.
Also, this code will not work if you don't have at least three records in your subform.
1. remove the
=[qryRandomSalesPersonNext subform].Form!EmpID
from txtRandom
2. copy this code into your main form:
Private Sub Form_Current()
Dim rs As DAO.Recordset
Set rs = Me.[qryRandomSalesPersonNext subform].Form.RecordsetClone
rs.MoveFirst
If Me.txtRandom = Me.FIRSTOwner Then
rs.MoveNext
If Me.txtRandom = Me.SECONDOwner Then
rs.MoveNext
End If
End If
If Not (rs.EOF Or rs.BOF) Then
Me.txtRandom = rs.Fields("EmpID")
End If
Set rs = Nothing
End Sub
then it should work.
Cheers,
Christian