Hello all,
I've gone through every "Dcount" post and am still banging my head against this one...so here goes.
I have an intersection table
tblActionMaterial
ActionID (pk)
MaterialID (pk)
In an Action subform I allow the user to enter materials used to complete that action. If a particular material has already been used for that action, I want a message box to pop up, notify the user, and ask them to pick something else. That way I don't end up with a pk violation.
So in Before Update I look at whether both the MaterialID and the ActionID already appear in the table:
Private Sub Material_BeforeUpdate(Cancel As Integer)
If DCount("[MaterialID] +
[ActionID]", "tblActionMaterial", "MaterialID = " & Me!
MaterialID And "ActionID = " & Me!ActionID) > 0 Then
MsgBox "This material is already chosen; pick another"
DoCmd.CancelEvent
End If
End Sub
The problem is that I keep getting a type error mismatch. The IDs in question are both numbers; can anyone see where I've gone astray in the syntax?
thanks!!
Joallyn
I've gone through every "Dcount" post and am still banging my head against this one...so here goes.
I have an intersection table
tblActionMaterial
ActionID (pk)
MaterialID (pk)
In an Action subform I allow the user to enter materials used to complete that action. If a particular material has already been used for that action, I want a message box to pop up, notify the user, and ask them to pick something else. That way I don't end up with a pk violation.
So in Before Update I look at whether both the MaterialID and the ActionID already appear in the table:
Private Sub Material_BeforeUpdate(Cancel As Integer)
If DCount("[MaterialID] +
[ActionID]", "tblActionMaterial", "MaterialID = " & Me!
MaterialID And "ActionID = " & Me!ActionID) > 0 Then
MsgBox "This material is already chosen; pick another"
DoCmd.CancelEvent
End If
End Sub
The problem is that I keep getting a type error mismatch. The IDs in question are both numbers; can anyone see where I've gone astray in the syntax?
thanks!!
Joallyn