Using this exact code to update a SQL database. Everything works fine until I try to close this frm_coils_add_new form using the DoCmd.Close command. The error states: "This action can't be carried out while processing a form or report event." No matter what I try to do it will not close automatically but I can close it using the X in the top right hand corner if I remove the DoCmd.Close command. The Text Box SC is the last data entry point on the form and when it is exited the below code runs. Any ideas ?
Private Sub SC_Exit(Cancel As Integer)
Dim stDocName, stLinkCriteria As String: Entered = Now()
Dim CN As ADODB.Connection: Dim rs As ADODB.Recordset
SQLa = "Insert Into CoilSpec.dbo.coilspec (Coil,StartLeft,TT,TPL,BDim,RPM,[Cross]," & _
"Pick1,Pick2,Pick3,Pick4,Pick5,Pick6,Pick7,Pick8,Pick9,Pick10,SpecialComments,Entered) values" & _
"(" & cmbWCoilNo & "," & Toggle112 & "," & TT & "," & TPL & "," & BDim & "," & RPM & "," & [Cross] & _
"," & P1 & "," & P2 & "," & P3 & "," & P4 & "," & P5 & "," & P6 & "," & P7 & "," & P8 & "," & P9 & _
"," & P10 & ", '" & SC & "' , '" & Entered & "' );"
Set CN = New ADODB.Connection: CN.Open "driver={SQL Server};" & _
"server=172.16.6.172;database=coilspec;uid=dtuttle;password=mpmadmin"
Set rs = CN.Execute(SQLa, , adCmdText)
CN.Close: Set rs = Nothing: Set CN = Nothing
MsgBox "Coil entry successfully saved"
DoCmd.Close
End Sub
Private Sub SC_Exit(Cancel As Integer)
Dim stDocName, stLinkCriteria As String: Entered = Now()
Dim CN As ADODB.Connection: Dim rs As ADODB.Recordset
SQLa = "Insert Into CoilSpec.dbo.coilspec (Coil,StartLeft,TT,TPL,BDim,RPM,[Cross]," & _
"Pick1,Pick2,Pick3,Pick4,Pick5,Pick6,Pick7,Pick8,Pick9,Pick10,SpecialComments,Entered) values" & _
"(" & cmbWCoilNo & "," & Toggle112 & "," & TT & "," & TPL & "," & BDim & "," & RPM & "," & [Cross] & _
"," & P1 & "," & P2 & "," & P3 & "," & P4 & "," & P5 & "," & P6 & "," & P7 & "," & P8 & "," & P9 & _
"," & P10 & ", '" & SC & "' , '" & Entered & "' );"
Set CN = New ADODB.Connection: CN.Open "driver={SQL Server};" & _
"server=172.16.6.172;database=coilspec;uid=dtuttle;password=mpmadmin"
Set rs = CN.Execute(SQLa, , adCmdText)
CN.Close: Set rs = Nothing: Set CN = Nothing
MsgBox "Coil entry successfully saved"
DoCmd.Close
End Sub