By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

Error 2585 - This action cannot be carried out

Andrew Thackray
P: 76
Can anyone explain this error. I have the following code in a button on a form

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdExit_Click()
  3.  
  4.    DoCmd.Close acForm, "ActivityMaintenance"
  5.  
  6.  
  7. End Sub
  8.  
It's my standard exit button code & I have never had problems with it before.

Now in one form it intermittently comes up with the error 2585 "This action canot be carried out while processing a form or report event.

I have researched this error on this forum & on the web an in all cases it is claimed that there is a procedure in the forms Activate or Open events that cause this.

I have removed any such code but this does not fix the problem.

The error seems to occur after a combobox click event triggers a complex update of quite a few records which causes a delay in responding to the on click event in the exit button. Howerver this code runs synchronously & therefore should be comleted before the exit button click event is activiated.

Is there any way of tracking the actual event that access is complaining about ??
Oct 30 '06 #1
Share this Question
Share on Google+
18 Replies


Andrew Thackray
P: 76
I have sort of solved the problem by changing the code to;

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdExit_Click()
  2.  
  3.     On Error Resume Next
  4.    DoCmd.Close acForm, "ActivityMaintenance"
  5.  
  6.  
  7. End Sub
  8.  
so now if the error occus it simply appears as if the button click did't work and a second button click seems to close the form OK.

However it is a clunky fix & I would really like to know what is happening
Oct 30 '06 #2

pks00
Expert 100+
P: 280
On Error Resume Next simply hides the error

If the update is running, or some other process related to that form, is running, u could wait for it to complete

try putting a DoEvents or DBEngine.Idle in
e.g.

Private Sub cmdExit_Click()

DoEvents
DoCmd.Close acForm, "ActivityMaintenance"

End Sub


or



Private Sub cmdExit_Click()

DBEngine.Idle
DoCmd.Close acForm, "ActivityMaintenance"

End Sub


if closing current form, have u just tried doing this
DoCmd.Close
Oct 30 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Can anyone explain this error. I have the following code in a button on a form

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdExit_Click()
  3.  
  4. DoCmd.Close acForm, "ActivityMaintenance"
  5.  
  6.  
  7. End Sub
  8.  
It's my standard exit button code & I have never had problems with it before.

Now in one form it intermittently comes up with the error 2585 "This action canot be carried out while processing a form or report event.

I have researched this error on this forum & on the web an in all cases it is claimed that there is a procedure in the forms Activate or Open events that cause this.

I have removed any such code but this does not fix the problem.

The error seems to occur after a combobox click event triggers a complex update of quite a few records which causes a delay in responding to the on click event in the exit button. Howerver this code runs synchronously & therefore should be comleted before the exit button click event is activiated.

Is there any way of tracking the actual event that access is complaining about ??
After the Update in the combo click events put a

DoEvents

command, this should process this procedure before anything else can happen.
Oct 30 '06 #4

Expert 5K+
P: 8,434
After the Update in the combo click events put a DoEvents command, this should process this procedure before anything else can happen.
Another possibility (based on VB6, but might work) - after hitting the error, tell the debugger to step. If it works anything like VB6, you may find it stops at the next statement in whatever is executing.
Oct 30 '06 #5

Andrew Thackray
P: 76
Putting in a doevents command doesnt work, i still get the error

TTrying to step throught the debugger also doesn't work , just repeats the error.

Also waiting a time before executing doesn't work - ie I have a standard routing for pausing the program while allowing processes to finish - this is the code

Expand|Select|Wrap|Line Numbers
  1.  
  2. private sub cmdExit_Click()
  3.  
  4.        TimeDelay 5,true
  5.         Docmd.close acform,"ActivityMaintenance"
  6.  
  7. End Sub
  8.  
  9. Public Function TimeDelay(Secs As Integer, ByVal AllowEvents As Boolean)
  10.  
  11.     ' Puts a delay of the number of seconds into the processing
  12.     Dim dStart As Date
  13.  
  14.     If Secs < 1 Then
  15.         Exit Function
  16.     End If
  17.     dStart = Now
  18.     Do Until DateDiff("s", dStart, Now) > Secs
  19.         If AllowEvents Then
  20.             DoEvents
  21.         End If
  22.     Loop
  23.  
  24. '
  25. End Function
  26.  
Oct 30 '06 #6

Expert 5K+
P: 8,434
...TTrying to step throught the debugger also doesn't work , just repeats the error.
Hm...

Could you debug when the error occurs, comment out your action whichi is producing it, then hit the Step key. If it's executing something elsewhere in your code, maybe this will stop at the next statement. If it doesn't reset the execution, that is.

Just a possibility...
Oct 30 '06 #7

MMcCarthy
Expert Mod 10K+
P: 14,534
Andrew

I meant to put the DoEvents in the procedure that's still running when the form is trying to close.

There is no error in the code to close the form it is simply that you cannot close a form while any procedure behind that form is still running. Procedures written behind a form in a form class module depend on the form being open. The error is occuring because you are trying to close a form that still has a procedure running.

I was suggesting that you throw a few Do Events into the aforementioned procedure to see if that would expedite the procedure to allow the form to close. No procedure should be taking this long to process.

Mary

Putting in a doevents command doesnt work, i still get the error

TTrying to step throught the debugger also doesn't work , just repeats the error.

Also waiting a time before executing doesn't work - ie I have a standard routing for pausing the program while allowing processes to finish - this is the code

Expand|Select|Wrap|Line Numbers
  1.  
  2. private sub cmdExit_Click()
  3.  
  4. TimeDelay 5,true
  5. Docmd.close acform,"ActivityMaintenance"
  6.  
  7. End Sub
  8.  
  9. Public Function TimeDelay(Secs As Integer, ByVal AllowEvents As Boolean)
  10.  
  11. ' Puts a delay of the number of seconds into the processing
  12. Dim dStart As Date
  13.  
  14. If Secs < 1 Then
  15. Exit Function
  16. End If
  17. dStart = Now
  18. Do Until DateDiff("s", dStart, Now) > Secs
  19. If AllowEvents Then
  20. DoEvents
  21. End If
  22. Loop
  23.  
  24. '
  25. End Function
  26.  
Oct 30 '06 #8

Andrew Thackray
P: 76
Mary

I put a doevents at the end of every sub & function and exit sub & exit function in the entire project. The error still occurs.

On researching the actual functioning of the doevents command I found out that it hands control back to the processor to clear its event queue from all sources before returning the control back to the calling routine.

This would imply that one doevents at any point in any program should let all pending processes complete, so the the suggestion to use a doevents call was a good one, it just didn't work.

does anyone know if events are triggered asynchroously or synchonously, ie when an event is triggered the triggering process halts until the triggered event processing ends or opens a new thread for the event process to process independantly of the calling process ?. If the event are asynchronous then this would explain the problem, but to resolve it I need some way of detecting what events are processing before I try to close the form.

Any suggestions ?


Killer42,

I tried your suggestion but the debugger merely stepped through remaining code in the procedure, though I did cut & paste the offending line into the immediate window & tried to execute it at several points later in the program. It still produced the error.
Oct 30 '06 #9

MMcCarthy
Expert Mod 10K+
P: 14,534

does anyone know if events are triggered asynchroously or synchonously, ie when an event is triggered the triggering process halts until the triggered event processing ends or opens a new thread for the event process to process independantly of the calling process ?. If the event are asynchronous then this would explain the problem, but to resolve it I need some way of detecting what events are processing before I try to close the form.

Any suggestions ?
To the best of my knowledge events are triggered and completed asynchonously.

One thing you could try is to put an unbound label on the form. You will have to default the caption to something " " will do. I've called it lblProcess.

Then at the beginning of each event put

Me.lblProcess.Caption = "Running: Description of Event"

At the end of each event put

Me.lblProcess.Caption = "Complete: Description of Event"

You could use a different textbox for each event for better control.

Most of them should change almost immediately to Complete

Mary
Oct 30 '06 #10

Andrew Thackray
P: 76
Ahhh!!

The penny is dropping, but slowly

The events are asynchronous, but the code in them executes until it issues an I/O call and relinquishes control to to another thread.

Subsequently most events will appear synchronous which explains why my code has worked before. Not only that but since clicking the exit button involves moving the mouse to the button before clicking there is usually at least 1 seconds delay between any previous event call and the click event, an eternity in computer terms.

However, because one my processes involves looping through and updating several hundred records, each I/O of which yields control to antoher thread, then it is possible that the click event can attempt to execute before the previous event proceure has completed.

I will try to resolve this with the following routine

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Public Type RunningProcess
  4.     IsRunning As Boolean
  5.     ProcessName As String
  6. End Type
  7.  
  8. Global Processes(500) As RunningProcess
  9.  
  10. Function SetReleaseProcess(ByRef SetUnset As Boolean, ByRef ProcessNo As Integer, ByRef ProcessName As String) As Boolean
  11.  
  12. ' Sets a flag when a precess starts and releases it when it exits. Returns True if there is an available flag to set, otherwise false if too many processes are running
  13. ' SetUnset is the state of the flag to be set
  14. ' ProcessNo points to the elemet in the array owned by the process. Returned to the  call process when setting a flag, provided by the calling process when releasing a flag
  15. ' ProcessName - the name of the process settin or onsetting the flag.
  16. ' txtBox points to a textbox where the running processes can be listed. Will be "" when no proceses are running
  17.  
  18.     Dim cnt As Integer
  19.     Dim Runningtxt As String
  20.     Select Case SetUnset
  21.         Case True
  22.             For cnt = 0 To 99
  23.                 If Processes(cnt).IsRunning = False Then
  24.                     Processes(cnt).IsRunning = True
  25.                     ProcessNo = cnt
  26.                     Processes(cnt).ProcessName = ProcessName
  27.                     SetReleaseProcess = True
  28.                     Exit For
  29.                 End If
  30.                 SetReleaseProcess = False
  31.             Next cnt
  32.         Case False
  33.             Processes(ProcessNo).IsRunning = False
  34.             Processes(ProcessNo).ProcessName = ""
  35.             SetReleaseProcess = True
  36.     End Select
  37.  
  38.     Runningtxt = ""
  39.     For cnt = 0 To 499
  40.         If Processes(cnt).IsRunning = True Then
  41.             If Len(Runningtxt) > 0 Then Runningtxt = Runningtxt & Chr(10)
  42.             Runningtxt = ProcessName & " running"
  43.         End If
  44.     Next cnt
  45.     TxtBox = Runningtxt
  46.  
  47. End Function
  48.  
  49.  
I'll let you know if this works. It also allows me to set a textbox with all running proceses for the user to look at while the program waits for them to finish. I will also hide the exit button until all processes have completed
Oct 31 '06 #11

Expert 5K+
P: 8,434
Just a cosmetic thing - you have a typo in your comments
Expand|Select|Wrap|Line Numbers
  1. ' Sets a flag when a precess starts ...
Oct 31 '06 #12

Andrew Thackray
P: 76
Thanks for noticing the typo Killer

The code works a treat. It immediately showed a recursion in one of the processes I wasn't aware of.

It also prevents the exit button from being pressed while processes are in progress and gives the user feedback on the processes that are triggered as they chgange the data on the form.

I'll use this as a standard in future where I have complex interactions with the user and the database.
Oct 31 '06 #13

NeoPa
Expert Mod 15k+
P: 31,343
Result Andrew!

This also helps those of us who've followed the thread.
Oct 31 '06 #14

Andrew Thackray
P: 76
Another error in the code. The first cnt loop has a limit of 99. It should be 499. I made the array large because I suspected that there may be recursive calls and I wanted to see how deep the recursion went.
Oct 31 '06 #15

Expert 5K+
P: 8,434
Another error in the code. The first cnt loop has a limit of 99. It should be 499. I made the array large because I suspected that there may be recursive calls and I wanted to see how deep the recursion went.
You mean I missed a bug? Boy, is my face red! :)

In my defense, I didn't actually read the code. Just glanced at the comments.
Oct 31 '06 #16

P: 37
I actually ran into this error for the first time when I was trying to close a form while a class module function was changing the page on a tab control. Solved it by simply saving a boolean that it should close and check for it's value after the tabpage change function took place. Perhaps someone who didnt think of this obvious solution like me in the first place may find use of this tip.
Apr 1 '10 #17

NeoPa
Expert Mod 15k+
P: 31,343
We often have members, and other public users, who go through threads looking for answers. This includes many threads that haven't been actively updated for years, but that doesn't mean they're not still in use.

Thanks for posting & Welcome to Bytes!
Apr 8 '10 #18

P: 1
I had a very similar problem to the one in the original post, and Killer42's suggestion above was very helpful. I stepped through my VBA code (MS Access 2007) to find the buggy code I needed to delete and that was causing the close action to fail. Thank you so much! This bug had been sitting in my code for years. I had previously put a band-aid on it until this morning when a user told me the application was crashing when they tried to open it.
Nov 18 '15 #19

Post your reply

Sign in to post your reply or Sign up for a free account.