There's a couple of ways to do this, but this will work:
Code:
Private Sub cboLocationPostedTo_AfterUpdate()
If Nz(Me.EmployeeNumber, "") <> "" Then
If DCount("*", "PostingTable", "EmployeeNumber & LocationPostedTo = '" & Me.EmployeeNumber & Me.cboLocationPostedTo & "'") > 0 Then
MsgBox "This Employee Has Been Posted to " & Me.LocationPostedTo & " Before!"
Me.cboLocationPostedTo = Null
End If
Else
MsgBox "You Must Select an Employee Number Before Selecting a Location!"
Me.cboLocationPostedTo = Null
EmployeeNumber.SetFocus
End If
End Sub
The above code assumes that
- The Table holding your data is named PostingTable
- The Field in the Table is named EmployeeNumber
- The Field in the Table is named LocationPostedTo
- The Control on the Form is named EmployeeNumber
- The Combobox for selecting a location is named cboLocationPostedTo
You'll need too change any of these names that aren't correct and replace them with your actual names.
The names in
Red are the
Fields, while those in
Blue are the
Controls.
"
EmployeeNumber & LocationPostedTo = '" & Me.EmployeeNumber & Me.cboLocationPostedTo & "'"
Linq
;0)>