Saving changes to subform on a navigation form

liddlem

Registered User.
Local time
Today, 05:45
Joined
May 16, 2003
Messages
339
When a student moves onto (or Off) the campus, then we do two things.
1. Update their attendance code (ID_Att_Code) in the Student table
2. We also record a MOVEMENT record in the Stu_Movement table

Therefore I am trying to automate the process so that when the user changes the ID_Att_Code field on the Student form, that it automatically opens the MOVEMENT form.
I have an afterupdate event on my ID_Att_Code combobox of the Forms![NAV_Boarding]![NavigationSubform] form as follows
Code:
If Me.ID_Att_Code.Column(6) [] Me.OnCampus Then
	'Get parameters to be applied to the Movement form when it is opened
        MyStud = Me.ID_Student
        MyAttCode = Me.ID_Att_Code
        MyAttCode_old = Me.ID_Att_Code.OldValue
        Me.OnCampus = Me.ID_Att_Code.Column(6)
    ' Open the movement form
    DoCmd.OpenForm "FRM_STU_Movement", acNormal, , , acFormAdd
	'Populate the fields
    Forms!frm_stu_MOVEMENT!FindStudent = MyStud
    Forms!frm_stu_MOVEMENT!ID_Student = MyStud
    Forms!frm_stu_MOVEMENT!ID_Att_Code = MyAttCode
    Forms!frm_stu_MOVEMENT!ID_Att_Code_Old = MyAttCode_old
    Forms!frm_stu_MOVEMENT!ID_Move_Type.SetFocus
	'requery the subforms
    Forms!frm_stu_MOVEMENT!FRM_STU_Movement_Sub001.Requery
    Forms!frm_stu_MOVEMENT!FRM_STU_MOVEMENT_Hist.Requery
End If
This all works fine - provided that the user completes the MOVEMENT form!
However - If the user decides that they have either assigned the wrong code OR need to cancel (undo) because they have selected the wrong student, then I need to update the calling form accordingly.
The problem is that the record on the calling form needs to be saved after it has received the update.
I have highlighted the block in the code below with asterisks where I am having issues.

On the MOVMENT form, I am applying the following relevant code.
Code:
Option Compare Database
Public MoveCxd      'Flag to indicate that the MOVEMENT was cancelled
Public CycleCount   'if ] 0 then don't display the Form_Undo message again

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrHand

If MoveCxd Then
  '  DoCmd.Close acForm, Me.Name
    MoveCxd = False
    Exit Sub
Else
    If IsNull(Me.ID_Move_Type) Then 'Or IsNull(Me.MOVE_NOTE) Or IsNull(Me.ID_Att_Code) Then
        MsgBox ("Please complete all required fields to SAVE changes - Or press ESC to cancel this record")
        Cancel = True
        Exit Sub
    End If
    If Me.ID_Att_Code = Me.ID_Att_Code.OldValue Then
        MsgBox ("You must type a reason for this move to SAVE changes - Or press ESC to cancel this record")
        Me.MOVE_NOTE.SetFocus
        Cancel = True
        Exit Sub
    End If
    ' make changes to the student table if all is good.
    MySql = "Update dbo_Stu_Student set ID_Att_Code = " & Me.ID_Att_Code & " where ID_Student = " & Me.FindStudent
    DoCmd.SetWarnings False
    DoCmd.RunSQL MySql
    DoCmd.SetWarnings True
End If
Exit Sub

ErrHand:
MsgBox ("FRM Stu_Movement - Before Update Err: " & Err.Number & " Descr : " & Err.Description)
If Err.Number = 2501 Then Resume Next 'Exit Sub
End Sub

Private Sub Form_Undo(Cancel As Integer)
On Error GoTo ErrHand
MyMsg = 0
    MyStud = Me.FindStudent
    MyAttCode_old = Me.ID_Att_Code_Old
    If CycleCount = 0 Then
    MyMsg = MsgBox("You pressed the ESC key. This will UNDO the movement record for this student" & vbCr _
    & "Are you sure that this is what you want to do", vbYesNo, "UNDO movement?")
        If MyMsg = vbYes Then
            If CurrentProject.AllForms("NAV_Boarding").IsLoaded Then
                Forms![NAV_Boarding]![NavigationSubform].Form![ID_Att_Code] = MyAttCode_old
                Forms![NAV_Boarding]![NavigationSubform].Form![OnCampus] = 99
                Forms![NAV_Boarding]![NavigationSubform].SetFocus
				'****************************
				'Bearing in mind that this code is in the MOVEMENT form, 
				'the form 'NAV_Boarding' has a subform called 'FRM_STU_Boarding_List'
				'How do I save the changes on this subform?
				' I have tried the following - None of which seem to work
                Forms!NAV_Boarding!NavigationSubform.Dirty = False
                Forms!NAV_Boarding!NavigationSubform!ID_Att_Code.Dirty = False
                FRM_STU_Boarding_List.Dirty = False
                DoCmd.Save acForm, Forms!NAV_Boarding!NavigationSubform.Requery
                DoCmd.Save acForm, Forms!NAV_Boarding!NavigationSubform.Refresh
				'****************************
            End If
            MoveCxd = True
            CycleCount = CycleCount + 1
            DoCmd.Close acForm, Me.Name
        End If
    End If
    If MyMsg = 7 Then
        CycleCount = 0
        Cancel = False
    End If
Exit Sub

ErrHand:
MsgBox ("FRM Stu_Movement - UNDO Err: " & Err.Number & " Descr : " & Err.Description)
If Err.Number = 2501 Then Resume Next
End Sub

Thanks
 

Users who are viewing this thread

Back
Top Bottom