Connecting Tech Pros Worldwide Help | Site Map

automation error server threw an exception

Newbie
 
Join Date: Oct 2009
Posts: 11
#1: 3 Weeks Ago
Expand|Select|Wrap|Line Numbers
  1. For Each objObj In .CurrentProject.AllForms
  2.  
  3.     DoEvents
  4.     intObj = intObj + 1
  5.     .DoCmd.OpenForm objObj.Name, acDesign, , , , acHidden
  6.  
  7.     Set objForm = .Forms(objObj.Name)
  8.     With objForm
  9. 'my task
  10. end with
  11.  .DoCmd.Close acForm, objObj.Name
  12. next
  13. :errorhand
  14. Resume Next

in the above code i am getiing automation error server throw an exception this error when one of the form gets opend after that next fomrs not get accessed it throws new error
automation error the object invoked has disconnected from its clients
Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,576
#2: 3 Weeks Ago

re: automation error server threw an exception


It is hard to say what is happening without knowing the details of what MyTask is doing. The error you quote will happen if the form is closed part way through processing of objForm.

You will need to trace the exact point at which the error occurs, by setting a breakpoint at, say, the start of the FOR-loop then manually stepping through each line executed until you determine which step is causing the error.

-Stewart
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#3: 3 Weeks Ago

re: automation error server threw an exception


When posting any code on here please :
  1. Ensure you have Option Explicit set (See Require Variable Declaration).
  2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
  3. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
  4. Ensure that the code in your post is enveloped within CODE tags. The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.
If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,213
#4: 3 Weeks Ago

re: automation error server threw an exception


Quote:

Originally Posted by nikhilkajrekar View Post

Expand|Select|Wrap|Line Numbers
  1. For Each objObj In .CurrentProject.AllForms
  2.  
  3.     DoEvents
  4.     intObj = intObj + 1
  5.     .DoCmd.OpenForm objObj.Name, acDesign, , , , acHidden
  6.  
  7.     Set objForm = .Forms(objObj.Name)
  8.     With objForm
  9. 'my task
  10. end with
  11.  .DoCmd.Close acForm, objObj.Name
  12. next
  13. :errorhand
  14. Resume Next

in the above code i am getiing automation error server throw an exception this error when one of the form gets opend after that next fomrs not get accessed it throws new error
automation error the object invoked has disconnected from its clients

I think you need to restructure your code, something similar to:
Expand|Select|Wrap|Line Numbers
  1. Dim obj As AccessObject
  2. Dim objProject As Object
  3. Dim frm As Form
  4.  
  5. Set objProject = Application.CurrentProject
  6.  
  7. For Each obj In objProject.AllForms
  8.   DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
  9.     Set frm = Forms(obj.Name)
  10.       With frm
  11.         'Simulate your Task(s) here
  12.         Debug.Print frm.Name & " | " & frm.Width
  13.           DoCmd.Close acForm, frm.Name
  14.       End With
  15. Next obj
Newbie
 
Join Date: Oct 2009
Posts: 11
#5: 3 Weeks Ago

re: automation error server threw an exception


Expand|Select|Wrap|Line Numbers
  1. On Error GoTo ErrorHandler
  2. Dim appAccess As New Access.Application
  3. Dim objForm As Form
  4. With appAccess
  5.  
  6. .OpenCurrentDatabase "E:\mydb\COMETV4.mdb"
  7. '.DoCmd.Minimize
  8.  
  9. DoEvents
  10.  
  11.  
  12.  
  13. Dim obj As AccessObject
  14. Dim objProject As Object
  15. Dim frm As Form
  16.  
  17. Set objProject = appAccess .CurrentProject
  18.  
  19. For Each obj In objProject.AllForms
  20.   DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
  21.     Set frm = Forms(obj.Name)
  22.       With frm
  23.         'Simulate your Task(s) here
  24.         Debug.Print frm.Name & " | " & frm.Width
  25.          Debug.Print frm.Section(0).Height
  26.           DoCmd.Close acForm, frm.Name
  27.       End With
  28.      infrm = infrm + 1
  29.       Label1.Caption = infrm + 1
  30. Next obj
  31.     .CloseCurrentDatabase
  32. End With
  33. ErrorHandler:
  34. If Err.Number < 0 Then
  35.  
  36. Label1.Caption = Err.Description
  37. End If
  38.  Resume Next
  39.  'End If
  40. End Sub
i restructured code but frm getting is nothing
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#6: 3 Weeks Ago

re: automation error server threw an exception


Quote:

Originally Posted by NeoPa View Post

When posting any code on here please :

  1. Ensure you have Option Explicit set (See Require Variable Declaration).
  2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
  3. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
  4. Ensure that the code in your post is enveloped within CODE tags. The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.
If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.

Nikhil, in case it wasn't clear, I posted this as a moderator. That means you must pay attention and follow these instructions otherwise I will take the matter further and apply an infraction to your account.

I am trying not to slap an infraction on it quite so soon after your joining the site, but frankly I'm being swamped with issues concerning you and these must stop.

Your code wouldn't even be allowed to be entered into the code window as it is, let alone compile. This wastes the time of our experts tidying up your code which you should be doing yourself before it ever sees this forum.

You have been warned.

Administrator.
Reply