padlocked17
Registered User.
- Local time
- Today, 17:06
- Joined
- Aug 29, 2007
- Messages
- 275
All -
I'm attempting to validate data being entered by using a DCount to check if a record exists that matches data and I would then like to check each entry that matches for a value in a particular column. I have sample code that checks if there is a number of records that match which are greater than 0 but I'm not sure how to process each record that matches for some criteria.
See the comments in the code for the big question on what I'm trying to do.
I'm attempting to validate data being entered by using a DCount to check if a record exists that matches data and I would then like to check each entry that matches for a value in a particular column. I have sample code that checks if there is a number of records that match which are greater than 0 but I'm not sure how to process each record that matches for some criteria.
See the comments in the code for the big question on what I'm trying to do.
Code:
Private Sub cboSelectMember_AfterUpdate()
Dim MemberID As String
Dim memberIDLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
'Determines if the SSN is a new record or not
If Me.NewRecord Then
If Me.cboSelectMember.Value & "" = "" Then
Me.Undo
Exit Sub
Else
MemberID = Me.cboSelectMember.Value
memberIDLinkCriteria = "[MemberID]=" & "'" & MemberID & "'"
'Check tblstudents table for duplicate SSN
If DCount("MemberID", "tblEnrollment", _
memberIDLinkCriteria) > 0 Then
'=====================================================================
'If the DCount returns an entry, we need to check each row to see if
'those rows actually have the "Graduated" column in the tblEnrollment
'marked as yes or no. If yes, we can add another enrollment. If no,
'that means they are in an active class and can't be added to another.
'=====================================================================
'Undo the duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Student Number " _
& MemberID & " is already enrolled in an active class." _
& vbCr & vbCr & "They are not able to attend more than one class concurrently.", _
vbInformation, "Duplicate Information"