Question : Error: "The action cannot be carried out while processing a form event."

I am getting the error on this line:
           DoCmd.Close acForm, "FRM_New_Student_Detail", acSaveNo

What event is processing that is preventing it from closing?

A screenshot is attached as well.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
Private Sub Form_Activate()
           
    Dim strCurrentID As String
    Dim strCurrentLast As String
    
    STU_ID = Forms![FRM_Main_Login_Students]![stuIDTextBox].Value
    LastName = Forms![FRM_Main_Login_Students]![lastNameTextBox].Value
    
    
    'Search for inputed values in dbo_STUDENT_DIM table.
    strCurrentID = Nz(DLookup("STU_ID", "dbo_STUDENT_DIM", "[STU_ID]=" & "[STU_ID]"))
    strCurrentLast = Nz(DLookup("LastName", "dbo_STUDENT_DIM", "STU_LAST_NAME='" & LastName & "' and  [STU_ID]= " & STU_ID))
        
    'If input is not found in TBL_Students, give error message and return to main login screen
    If strCurrentID = -1 Or strCurrentLast = "" Then
        If MsgBox("The information you entered did not match any IWU student records.  Please try again.", vbOKOnly, "Invalid Entry") = vbOK Then
           DoCmd.Close acForm, "FRM_New_Student_Detail", acSaveNo
           DoCmd.OpenForm "FRM_Main_Login_Students", acNormal
           Exit Sub
        End If
    'If input is found, add all user data into the fields of TBL_Students
    Else
         FirstName = STU_FIRST_NAME
         Middle = STU_MIDDLE_NAME
         LastName = STU_LAST_NAME
         Campus_Box = STU_CAMPUS_ADDR1
         Phone = STU_CELL_PHONE
         Email = STU_EMAIL
         Address = STU_ADDR1
         City = STU_CITY
         State_Abbreviation = STU_STATE
         Zip = STU_ZIP
    End If
End Sub

Answer : Error: "The action cannot be carried out while processing a form event."

move the codes in the Activate event to the Open event
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
Private Sub Form_Open(cancel as integer)
           
    Dim strCurrentID As String
    Dim strCurrentLast As String
    
    STU_ID = Forms![FRM_Main_Login_Students]![stuIDTextBox].Value
    LastName = Forms![FRM_Main_Login_Students]![lastNameTextBox].Value
    
    
    'Search for inputed values in dbo_STUDENT_DIM table.
    strCurrentID = Nz(DLookup("STU_ID", "dbo_STUDENT_DIM", "[STU_ID]=" & "[STU_ID]"))
    strCurrentLast = Nz(DLookup("LastName", "dbo_STUDENT_DIM", "STU_LAST_NAME='" & LastName & "' and  [STU_ID]= " & STU_ID))
        
    'If input is not found in TBL_Students, give error message and return to main login screen
    If strCurrentID = -1 Or strCurrentLast = "" Then
        If MsgBox("The information you entered did not match any IWU student records.  Please try again.", vbOKOnly, "Invalid Entry") = vbOK Then
      '     DoCmd.Close acForm, "FRM_New_Student_Detail", acSaveNo
           '*****
           'this will Cancel the opening of the form

           Cancel=true
           
           DoCmd.OpenForm "FRM_Main_Login_Students", acNormal
           Exit Sub
        End If
    'If input is found, add all user data into the fields of TBL_Students
    Else
         FirstName = STU_FIRST_NAME
         Middle = STU_MIDDLE_NAME
         LastName = STU_LAST_NAME
         Campus_Box = STU_CAMPUS_ADDR1
         Phone = STU_CELL_PHONE
         Email = STU_EMAIL
         Address = STU_ADDR1
         City = STU_CITY
         State_Abbreviation = STU_STATE
         Zip = STU_ZIP
    End If
End Sub
Random Solutions  
 
programming4us programming4us