Option Compare Database Private Sub AddEnrollment_Click() On Error GoTo Err_AddEnrollment_Click 'Look for a match in the Enrollment table Dim CustNum As Integer Dim dbs As Database Dim rst As Recordset Dim didFind As Boolean Set dbs = CurrentDb Set rst = dbs.OpenRecordset("Enrollment") 'Look for a match in the Enrollment table didFind = False If (Not rst.EOF) Then rst.MoveFirst End If i = 0 Do While (Not rst.EOF() And didFind = False) If (Me.ClassID = rst![ClassID] And Me.CustID = rst![CustID]) Then 'If found, delete it rst.Delete didFind = True End If If (Not didFind) Then rst.MoveNext End If Loop 'just in case... If (didFind = False) Then MsgBox ("Entry not found, there was an error") Exit Sub End If 'Create a new record rst.AddNew rst![CustID] = Me.CustID rst![ClassID] = Me.ClassID rst![Amount Paid] = Me.AmountPaid rst![Paid Date] = Me.PaidDate rst![Entered By] = Me.EnteredBy rst![Entered Date] = Me.EnteredDate rst![Refunded] = Me.Check66 If (Me.Check66 = True) Then rst![Refunded Date] = Me.Text61 End If rst.Update MsgBox ("Successful Update of " & Me.lname & "," & Me.fname & " in class " & Me.ClassID) Me.Refresh AmountPaid = AmountPaid.DefaultValue PaidDate.Value = Date Refunded = False ClassID.SetFocus Forms![nrv - Change Enrollment]![All classes a specified custID enrolled in subform].Form.Requery Exit_AddEnrollment_Click: Exit Sub Err_AddEnrollment_Click: MsgBox "An error occured. Most likely, this class is already enrolled for this customer." Resume Exit_AddEnrollment_Click End Sub Private Sub ClassID_Change() 'When something in the combo box is entered, update the info.. Dim THEclassID As String Dim THEcustID As Integer Dim TheAmtPD As Currency Dim ThePDate As Date Dim TheRDate As Date Dim TheRef As Boolean Me.Refresh 'Grab important info THEcustID = Me.CustID If (IsNull(Me.ClassID)) Then Exit Sub Else THEclassID = Me.ClassID End If 'Find the matching rst for this enrollment Dim didFind As Boolean Dim rst2 As Recordset Set rst2 = CurrentDb.OpenRecordset("Enrollment") didFind = False If (Not rst2.EOF) Then rst2.MoveFirst End If i = 0 Do While (Not rst2.EOF() And didFind = False) If (Me.ClassID = rst2![ClassID] And Me.CustID = rst2![CustID]) Then 'Set DidFind to True didFind = True End If If (Not didFind) Then rst2.MoveNext End If Loop If (didFind = False) Then MsgBox ("NO MATCH") Exit Sub End If 'rst2 now holds the current match 'Update all the field information 'TheEby = IIf(IsNull(rst2![Entered By]), "", rst2![Entered By]) TheAmtPD = rst2![Amount Paid] ThePDate = rst2![Paid Date] If (IsNull(rst2![Refunded Date])) Then TheRDate = Date Else TheRDate = rst2![Refunded Date] End If TheRef = rst2![Refunded] 'Now update the fields AmountPaid = TheAmtPD PaidDate = ThePDate Text61 = TheRDate Check66 = TheRef ' EnteredBy = TheEby 'Find the matching class name and time... Dim ClassName As String Dim ClassLocation As String Set rst2 = CurrentDb.OpenRecordset("Class") didFind = False If (Not rst2.EOF) Then rst2.MoveFirst Else Exit Sub End If i = 0 Do While (Not rst2.EOF() And didFind = False) If (Me.ClassID = rst2![ClassID]) Then If (IsNull(rst2![Name])) Then ClassName = "" Else ClassName = rst2![Name] End If If (IsNull(rst2![Location])) Then ClassLocation = "" Else ClassLocation = rst2![Location] End If didFind = True End If If (Not didFind) Then rst2.MoveNext End If Loop cName = ClassName cLoc = ClassLocation End Sub Private Sub CloseEnrollForm_Click() On Error GoTo Err_CloseEnrollForm_Click DoCmd.Close Exit_CloseEnrollForm_Click: Exit Sub Err_CloseEnrollForm_Click: MsgBox Err.Description Resume Exit_CloseEnrollForm_Click End Sub Private Sub Form_Open(Cancel As Integer) End Sub Private Sub DeleteRecordButton_Click() On Error GoTo Err_DeleteRecordButton_Click Dim rst2 As Recordset Set rst2 = CurrentDb.OpenRecordset("Enrollment") didFind = False If (Not rst2.EOF) Then rst2.MoveFirst End If i = 0 Do While (Not rst2.EOF() And didFind = False) If (Me.ClassID = rst2![ClassID] And Me.CustID = rst2![CustID]) Then 'Set DidFind to True rst2.Delete didFind = True End If If (Not didFind) Then rst2.MoveNext End If Loop If (didFind = True) Then MsgBox ("Successfully deleted") Else MsgBox ("Not Deleted") End If Forms![nrv - Change Enrollment]![All classes a specified custID enrolled in subform].Form.Requery Exit_DeleteRecordButton_Click: Exit Sub Err_DeleteRecordButton_Click: MsgBox Err.Description Resume Exit_DeleteRecordButton_Click End Sub