Sorry for the long post
I have a complex 'New student enrolment' form that contains 3 subforms on it. I need to ensure that THREE conditions are met before the user is allowed to save the record.
Access 2016 front end and SQL 2016 back end.
The Parent form is the 'Enrolment Enquiry' form.
The SubForms are:
Students - Can add more than one student
UNDERLYING QUERY FOR THE STUDENTS
Family - Can add more than one family member
UNDERLYING QUERY FOR THE FAMILY
FamilyAddress - Can add more than one address
UNDERLYING QUERY FOR THE FAMILYADDRESS
When capturing the data, I need to ensure that
1. EACH student (on the STUDENTS subform) is linked (related) to at least one Family member (on the Family Subform) and
2. EACH Family Member must be linked to at least ONE address on the Family Address subform.
I have added a 'Btn_Save' for the user to press when they want to save the record -
I am getting stuck at the point that I need to cycle through the recordset
The two lines where I am having difficulty are:
' The following line throws a 3061 error (Too few paremeters. Expected 1)
and
'Check that this first student has at least one family member
The full code is as follows:
I have a complex 'New student enrolment' form that contains 3 subforms on it. I need to ensure that THREE conditions are met before the user is allowed to save the record.
Access 2016 front end and SQL 2016 back end.
The Parent form is the 'Enrolment Enquiry' form.
The SubForms are:
Students - Can add more than one student
UNDERLYING QUERY FOR THE STUDENTS
Code:
SELECT dbo_ENR_StudentDtl.ID_EnrDtl, dbo_ENR_StudentDtl.ID_EnrHdr, dbo_STU_Student.ID_Student
FROM dbo_ENR_StudentDtl INNER JOIN dbo_STU_Student ON dbo_ENR_StudentDtl.ID_Student = dbo_STU_Student.ID_Student
WHERE (((dbo_ENR_StudentDtl.ID_EnrHdr)=[Forms]![FRM_ENR_EnrolmentHdr]![ID_EnrHdr]));
Family - Can add more than one family member
UNDERLYING QUERY FOR THE FAMILY
Code:
SELECT dbo_CMTY_FamilyRelations.ID_Student, dbo_CMTY_FamilyRelations.ID_CMTY, Trim([dbo_CMTY_Member].[NAME_Surname]) & ", " & Trim([dbo_CMTY_Member].[NAME_First]) AS Member, dbo_CMTY_FamilyRelations.ID_CMTY_RelType, dbo_CMTY_FamilyRelations.FLAG_Responsible_Adult, dbo_CMTY_FamilyRelations.FLAG_StudentResidesWith, dbo_CMTY_FamilyRelations.FLAG_GUARDIAN, dbo_CMTY_FamilyRelations.ALT_GUARDIAN_SEQ, dbo_CMTY_FamilyRelations.FLAG_StuMayContact, dbo_CMTY_FamilyRelations.FLAG_StuAllowedAtAddress, dbo_CMTY_FamilyRelations.FamRelNotes, dbo_CMTY_FamilyRelations.Obsolete
FROM dbo_CMTY_FamilyRelations INNER JOIN dbo_CMTY_Member ON dbo_CMTY_FamilyRelations.ID_CMTY = dbo_CMTY_Member.ID_CMTY
WHERE (((dbo_CMTY_FamilyRelations.ID_Student) In (select ID_Student from [QRY_ENR_Students]
)))
ORDER BY dbo_CMTY_FamilyRelations.ID_Student, Trim([dbo_CMTY_Member].[NAME_Surname]) & ", " & Trim([dbo_CMTY_Member].[NAME_First]);
UNDERLYING QUERY FOR THE FAMILYADDRESS
Code:
SELECT dbo_CMTY_AddressLink.ID_CMTY_AddressLink, Trim([dbo_CMTY_Member].[NAME_Surname]) & ", " & Trim([dbo_CMTY_Member].[Name_First]) AS Member, dbo_CMTY_AddressLink.ID_CMTY, dbo_CMTY_AddressLink.ID_CMTY_Address, dbo_CMTY_AddressLink.CMTY_AddressType, dbo_CMTY_AddressLink.CorrespondenceAddr, dbo_CMTY_AddressLink.Care_Of, dbo_CMTY_AddressLink.PO_Box, dbo_CMTY_AddressLink.MailToPMB, dbo_CMTY_AddressLink.LinkNotes
FROM (dbo_CMTY_AddressLink INNER JOIN QRY_ENR_FamilyRelations ON dbo_CMTY_AddressLink.ID_CMTY = QRY_ENR_FamilyRelations.ID_CMTY) INNER JOIN dbo_CMTY_Member ON QRY_ENR_FamilyRelations.ID_CMTY = dbo_CMTY_Member.ID_CMTY;
When capturing the data, I need to ensure that
1. EACH student (on the STUDENTS subform) is linked (related) to at least one Family member (on the Family Subform) and
2. EACH Family Member must be linked to at least ONE address on the Family Address subform.
I have added a 'Btn_Save' for the user to press when they want to save the record -
I am getting stuck at the point that I need to cycle through the recordset
The two lines where I am having difficulty are:
' The following line throws a 3061 error (Too few paremeters. Expected 1)
Code:
Set rs = CurrentDb.OpenRecordset("QRY_ENR_Students", dbOpenDynaset, dbSeeChanges)
'Check that this first student has at least one family member
Code:
MyFam = DCount("ID_CMTY", "QRY_ENR_FamilyRelations", "ID_Student = " & rs.Fields(0))
The full code is as follows:
Code:
Private Sub Btn_Save_Click()
Dim MyCmtyCount
Dim MyStudCount As Integer
Dim MyRelationCount As Integer
MyCmtyCount = 0
MyRelationCount = 0
MyStudCount = 0
'Check that at least ONE student exists
MyStudCount = DCount("ID_EnrHdr", "QRY_ENR_Students", "ID_EnrHdr = " & Me.ID_EnrHdr)
If MyStudCount < 1 Then
MyMsg = MsgBox("You must connect at least ONE student to the enrolment process" & vbCr _
& "The record will not be completed at this time", vbOKOnly, "Missing STUDENT information")
Exit Sub
End If
'Count how many COMMUNITY MEMBERS (Relations) have been added - There must be at least ONE
MyCmtyCount = DCount("ID_Cmty", "QRY_ENR_CMTY_Members", "ID_EnrHdr = " & Me.ID_EnrHdr)
If MyCmtyCount < 1 Then
MyMsg = MsgBox("You must connect at least ONE Community Member to the enrolment process" & vbCr _
& "The record will not be completed at this time", vbOKOnly, "Missing COMMUNITY MEMBER information")
Exit Sub
End If
''For each STUDENT in the enrolment application, check that they are connected to at least ONE Community Member
On Error GoTo Err_Proc
Dim rs As DAO.Recordset
' The following line throws a 3061 error (Too few paremeters. Expected 1)
Set rs = CurrentDb.OpenRecordset("QRY_ENR_Students", dbOpenDynaset, dbSeeChanges)
AllFam = True 'assume that BOF is connected to a maily member
If rs.RecordCount <> 0 Then
*rs.MoveFirst
While Not rs.EOF
'Check that this first student has at least one family member
MyFam = DCount("ID_CMTY", "QRY_ENR_FamilyRelations", "ID_Student = " & rs.Fields(0))
If MyFam > 0 And AllFam Then
AllFam = True
Else
AllFam = False
GoTo Exit_Proc
End If
rs.MoveNext
Wend
End If
' Now check the addresses
' copy code from above and change accordingly
Exit_Proc:
On Error Resume Next
*rs.Close
Set rs = Nothing
If Not AllFam Then
MyMsg = MsgBox("You must connect at least ONE student to the enrolment process" & vbCr _
& "The record will not be completed at this time", vbOKOnly, "Missing Student/Parent/Address information")
Cancel = True
Exit Sub
End If
Exit Sub
Err_Proc:
MsgBox Err.Number & " " & Err.Description
Err.Number = 0
Resume Exit_Proc
End Sub