Thanks for any info you might have.
I have an Access database that is tracking Student Grades. Part of the gig is mapping their future courses [CourseID].
What I'm trying to do is either narrow down a Combobox as courses are selected (remove a course if it has already been entered), or stay away from the Access built-in error messages.
One student can have multiple terms [ProgramID], and multiple courses per term [CourseID]. These two fields make up the Key on the Record source for OOSMap table.
I have a Main form (OOSMain) - a subform (OOSMap) - and a subform off OOSMap (OOSMapSubForm).
The code I have works for the [CourseID] but doesn't when the [ProgramID] is factored in. It won't let me enter a [CourseID] for a second map (required) if it exists in the first map (ignores the [ProgramID] part of the key).
Expand|Select|Wrap|Line Numbers
- Private Sub Form_BeforeUpdate(Cancel As Integer)
- DoCmd.SetWarnings False
- Dim Answer As Variant
- Answer = DLookup("[CourseID]", "OOSMap", "[CourseID] = '" & Me.CourseID & "'")
- If Not IsNull(Answer) Then
- MsgBox "Course already exists in this Map," & vbCrLf & "Please select another course", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"
- Cancel = True
- Me.CourseID.Undo
- DoCmd.SetWarnings True
- Else:
- End If
- End Sub