On error, the rest of the code is particular to that form/subform, so the action needs to happen there.
On error, the rest of the code is particular to that form/subform, so the action needs to happen there.
Is the check not particular to that subform to? As it needs to look at the individual behaviour which has changed.
#165
(needs 10 characters to post!)
Yeah sorry - didn't notice it since it was the last one on the page. So how would I do it? Name them on the AfterUpdate then reference them on the module?
Do you know what parameter means? (trying to write this as a question, nothing else?)
In what context?
Passing values to subroutines - those are called parameters.
Oh, no. I'll give them a Google
In form: If SubroutineName(parameter,parameter,,,)=true/false then
Public SubroutineName(parm1,parm2,,,,)
....code
SubroutineName=True/False
so something like...
Public ChangeBehaviour(AssessmentID,BehaviourID,ResponseI D)
Dim BehID As Long
On Error Resume Next
BehID = DLookup("BehaviourID", "TblAssessmentDetails", "BehaviourID=" & Me!BehaviourID & " AND AssessmentID=" & Me!AssessmentID & " AND ResponseID<>" & Me!ResponseID)
If BehID > 0 Then
MsgBox "This behaviour has already been selected."
Cancel = True
ChangeBehaviour=True
End If
on form:
If ChangeBehaviour=True Then
*undo insert of row/change of behaviour* <-I don't know where to start with that
Cancel=true - wrong place
Otherwise great!
In the form you will have what you have now.
Oh, so like this?
on form:Code:Public ChangeBehaviour(AssessmentID,BehaviourID,ResponseID) Dim BehID As Long On Error Resume Next BehID = DLookup("BehaviourID", "TblAssessmentDetails", "BehaviourID=" & Me!BehaviourID & " AND AssessmentID=" & Me!AssessmentID & " AND ResponseID<>" & Me!ResponseID) If BehID > 0 Then MsgBox "This behaviour has already been selected." ChangeBehaviour=True End If
Code:If ChangeBehaviour=True Then Cancel=true End if *undo insert of row/change of behaviour* <-I don't know where to start with that
You're using "me" in a global sub?
Got halfway through a reply to this last night and forgot about it. That was a copy and paste error, but how do I reference it?
Do I just dim BehaviourID on all 3 subforms or something?
The value is in the parameter, so just remove the Me. BehaviourID is already defined on all three subforms, it is on the Record Source.