473,418 Members | 2,086 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Error 2585 - This action cannot be carried out

Andrew Thackray
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
19 27070
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
280 Expert 100+
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
14,534 Expert Mod 8TB
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
Killer42
8,435 Expert 8TB
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
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
Killer42
8,435 Expert 8TB
...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
14,534 Expert Mod 8TB
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
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
14,534 Expert Mod 8TB

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
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
Killer42
8,435 Expert 8TB
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
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
32,556 Expert Mod 16PB
Result Andrew!

This also helps those of us who've followed the thread.
Oct 31 '06 #14
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
Killer42
8,435 Expert 8TB
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
robjens
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
32,556 Expert Mod 16PB
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
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
kkarbasian
1 Bit
hi
i had this error same and it is very simple in end of vba window had somthing note please delete them retype your code and ...
Aug 6 '21 #20

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

Similar topics

2
by: Abhijit Bhadra | last post by:
Hi , I was trying to build my project in VC with latest Service Packs but got this error . C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2440: 'return' :...
2
by: Tom Bray | last post by:
Ok I am baffled I can not figure out this problem. I am getting the following error: Portal Error - A DropDownList cannot have multiple items selected. Error information Name Value Message...
2
by: Simon Harris | last post by:
I have created a web service, which when I call in my browser presents the text form etc. When I click the button, I get this error: System.ArgumentException: Cannot convert to System.Int32....
3
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'...
1
by: Adrian Turner | last post by:
I am just starting developing with .Net(Have used asp for years). I have created a very simple upload page which once uploaded opens the file(excel) and displays the data. If I Attempt to re-run...
1
by: Jean Stachler | last post by:
We have a VB app that is set off automatically when a file exists in a certain directory. The file contains a listing of part numbers which the program reads and than retrieves drawings which are in...
1
by: td0g03 | last post by:
I have no idea why am I getting an error C2664: 'parseInput' : cannot convert parameter 2 from 'main::WORD_STRUCT ' to 'struct WORD_STRUCT ' #include <stdio.h> #include <stdlib.h> #include...
5
by: slizorn | last post by:
well the error i get is the title above: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char' error is form this line searchTree(treeObj->root ,data1.c_str());...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.