Run-time error: '2585'

Randomblink

The Irreverent Reverend
Local time
Today, 13:49
Joined
Jul 23, 2001
Messages
279
Here is the error I am getting on a Form I created.
Run-time error '2585'

This action can't be carried out while processing a form or report event.

This is the LostFocus event for a textbox on my Form.
Code:
Private Sub Proj_Title_LostFocus()
Dim strSQLCriteria As String, qry As String, Response As VbMsgBoxResult
On Error GoTo Err_ProjTitle

Select Case IsNull(Proj_Title)
    Case True: GoSub Reminder
    Case False: GoSub Link
End Select

Exit_ProjTitle:
    Exit Sub

Reminder:
    Response = MsgBox("You must enter a Project Title to Continue. Do you wish to continue?" & Chr(13) & Chr(10) & "Press YES if you wish to continue." & Chr(13) & Chr(10) & "Press NO if you wish to exit.", vbYesNo, "Project Title Required")
    Select Case Response
        Case vbYes: Proj_Title.SetFocus
        Case vbNo: basicActions "Close Form", Me
    End Select
    Response = 0
    Return

SureYouWantToLeave:
    Response = MsgBox("If you leave now, no new Project will be created. Are you sure you wish to do this?" & Chr(13) & Chr(10) & "Press YES to exit." & Chr(13) & Chr(10) & "Press NO to enter a Project Title.", vbYesNo, "Exit Verification")
    Select Case Response
        Case vbYes: Exit Sub: basicActions "Close Form", Me
        Case vbNo: Proj_Title.SetFocus
    End Select
    Response = 0
    Return

Link:
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    DoCmd.SetWarnings False
    strSQLCriteria = "INSERT INTO [tbl_LINK_ProjectBasics-Employee] (Proj_ID, Empl_ID) VALUES (" & CInt(Me!Proj_ID) & ", " & CInt(UsrDtl("EmployeeID")) & ");"
    DoCmd.RunSQL strSQLCriteria
    pge_CityEmployees.Visible = True:
    Proj_Bdgt.SetFocus: Proj_Title.Enabled = False
    Return
    
Err_ProjTitle:
    errMessage Err
    Resume Exit_ProjTitle

End Sub


This is the Public Function that is called from the LostFocus event above...
Code:
Public Function basicActions(bscAction As String, Optional trgtForm As Form)
On Error GoTo Err_basicActions

Select Case bscAction
    Case "Close Form": GoSub CloseForm
    Case "Save Current Record": GoSub SaveCurRec
    Case "Shut Down Application": GoSub CloseALL
    Case "Add New Record": GoSub AddNewRec
End Select

Exit_basicActions:
    Exit Function
    
AddNewRec:
    DoCmd.GoToRecord , , acNewRec
    Return
    
SaveCurRec:
    DoCmd.RunCommand acCmdSaveRecord
    Return
    
CloseALL:
    Application.Quit acQuitSaveAll
    Return

CloseForm:
    DoCmd.Close acForm, trgtForm.Name, acSaveNo
    If Forms.Count = 0 Then Application.Quit acQuitSaveAll
    Return
    
Err_basicActions:
    errMessage Err
    Resume Exit_basicActions
    
End Function

Can anyone tell me why I am not able to CLOSE the form while processing the LostFocus event? AND If I CAN'T do this, how do I close the form? Any ideas?

Thanks in advance...
Any help would be greatly appreciated...
 
Ummm. I forgot to explain WHERE the error happens...

The error happens at EVERY point where it tries to DoCmd.Close...

I cannot close the form from inside the LostFocus event...

All I want to do is close the form at that point...
 
Start by commenting out the On Error lines to see which line is causing the problem.
 
It is still trying to process your Gosub thread, but you are trying to close the form mid-stream. Try using a CancelEvent prior to closing or re-write excluding Gosubs, which, is always good advice.
 

Users who are viewing this thread

Back
Top Bottom