Message says "this action can't be carried out when processing a form".
The line of code is:
Requery
DoCmd.Close acForm, "frmEnterNewDNCAR", acSaveNo
I have tried to close this form in many different ways, including a call to a function in a module that attempts to close the form. Note that a 'requery' is performed just before the close to write the record.
My suspicion is that the error indicates another problem that I am not addressing but I do not know what it is! B-(
The context is that a txtbox when completed performs a dLookup on the LostFocus event to see if the data has already been entered into indexed field of the table. If it has then the user is notified that their entry is duplicate data giving them a choice of CANCEL to they may re-key the entry or OK where I write the record, requery the table, close the form and return them to the main menu. But no matter what I do, this error keeps coming up! makes me wonder how any form gets closed!
Below is my code for this event. Any advice is appreciated!
Sorrells
PS: I tried t close the form in the Module where the function Delete_Record is located and still receive this error.
================================================================
Private Sub txtLogNumber_LostFocus()
Dim GetValue As String 'hold return value from dLookup function
Dim RetValue As String 'hold value for message box
Dim db_Name As String, Form_Close As String, Form_Open As String, Table_Name As String, Index_Field As String, Index_Data As String 'VARIABLES FOR DELETE_RECORD FUNCTION
' DEC-I CODING - CHECK FOR DUPLICATE LOG NUMBERS
' The code below performs a check on the LogNumber entered by the user
' to make sure that it is not a duplicate with a dLookup function.
' If it is a duplicate, the user has a choice to CANCEL if the
' LogNumber had been miskeyed, or OK if the number is correct.
' Pressing OK returns the user to the Main Menu so that they can
' contact the DNCAR Administrator to resolve the conflict.
'
txtLogNumber = Format(txtLogNumber, "000000"
GetValue = "" & DLookup("[PartNumber]", "DNCARHeader", "[LogNumber] = '" & txtLogNumber & "'"
If txtLogNumber = "DupRec" Then
GetValue = "dup rec"
End If
If GetValue = "" Or IsNull(GetValue) Then
' do nothing as no duplicate lognumber was found
Else
RetValue = MsgBox("This is a duplicate Log Number. If you miskeyed it, press CANCEL, if correct, notify the Administrator as this number cannot be used. Pres OK to return to the Main Menu", vbOKCancel)
If RetValue = vbCancel Then
txtLogNumber = "DupRec" 'this text should be replaced by the user
txtSuffix.SetFocus
txtLogNumber.SetFocus
Else
db_Name = "L:\DNCAR_db\IA-Maint\Development\Admin_Test\DNCAR_Data.mdb"
Form_Close = "frmEnterNewDNCAR" ' name of the form to be closed
Form_Open = "frmmenu" ' name of the form to be opened
txtLogNumber = "DupRec" ' provide a value to search for in fuction
Table_Name = "DNCARHeader" ' name of table to be opened to delete record
Index_Field = "LogNumber" ' name of field in table that is indexed
Index_Data = txtLogNumber ' data value in index field to search for
Requery 'force writing of the record
DoCmd.Close acForm, "frmEnterNewDNCAR", acSaveNo 'close form fails with the 2585 ERROR
' [Forms]![frmEnterNewDNCAR].Visible = False
Call Delete_Record(db_Name, Form_Close, Form_Open, Table_Name, Index_Field, Index_Data)
End If
End If
The line of code is:
Requery
DoCmd.Close acForm, "frmEnterNewDNCAR", acSaveNo
I have tried to close this form in many different ways, including a call to a function in a module that attempts to close the form. Note that a 'requery' is performed just before the close to write the record.
My suspicion is that the error indicates another problem that I am not addressing but I do not know what it is! B-(
The context is that a txtbox when completed performs a dLookup on the LostFocus event to see if the data has already been entered into indexed field of the table. If it has then the user is notified that their entry is duplicate data giving them a choice of CANCEL to they may re-key the entry or OK where I write the record, requery the table, close the form and return them to the main menu. But no matter what I do, this error keeps coming up! makes me wonder how any form gets closed!
Below is my code for this event. Any advice is appreciated!
Sorrells
PS: I tried t close the form in the Module where the function Delete_Record is located and still receive this error.
================================================================
Private Sub txtLogNumber_LostFocus()
Dim GetValue As String 'hold return value from dLookup function
Dim RetValue As String 'hold value for message box
Dim db_Name As String, Form_Close As String, Form_Open As String, Table_Name As String, Index_Field As String, Index_Data As String 'VARIABLES FOR DELETE_RECORD FUNCTION
' DEC-I CODING - CHECK FOR DUPLICATE LOG NUMBERS
' The code below performs a check on the LogNumber entered by the user
' to make sure that it is not a duplicate with a dLookup function.
' If it is a duplicate, the user has a choice to CANCEL if the
' LogNumber had been miskeyed, or OK if the number is correct.
' Pressing OK returns the user to the Main Menu so that they can
' contact the DNCAR Administrator to resolve the conflict.
'
txtLogNumber = Format(txtLogNumber, "000000"
GetValue = "" & DLookup("[PartNumber]", "DNCARHeader", "[LogNumber] = '" & txtLogNumber & "'"
If txtLogNumber = "DupRec" Then
GetValue = "dup rec"
End If
If GetValue = "" Or IsNull(GetValue) Then
' do nothing as no duplicate lognumber was found
Else
RetValue = MsgBox("This is a duplicate Log Number. If you miskeyed it, press CANCEL, if correct, notify the Administrator as this number cannot be used. Pres OK to return to the Main Menu", vbOKCancel)
If RetValue = vbCancel Then
txtLogNumber = "DupRec" 'this text should be replaced by the user
txtSuffix.SetFocus
txtLogNumber.SetFocus
Else
db_Name = "L:\DNCAR_db\IA-Maint\Development\Admin_Test\DNCAR_Data.mdb"
Form_Close = "frmEnterNewDNCAR" ' name of the form to be closed
Form_Open = "frmmenu" ' name of the form to be opened
txtLogNumber = "DupRec" ' provide a value to search for in fuction
Table_Name = "DNCARHeader" ' name of table to be opened to delete record
Index_Field = "LogNumber" ' name of field in table that is indexed
Index_Data = txtLogNumber ' data value in index field to search for
Requery 'force writing of the record
DoCmd.Close acForm, "frmEnterNewDNCAR", acSaveNo 'close form fails with the 2585 ERROR
' [Forms]![frmEnterNewDNCAR].Visible = False
Call Delete_Record(db_Name, Form_Close, Form_Open, Table_Name, Index_Field, Index_Data)
End If
End If