• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2779
  • Last Modified:

Run-time error '2766'

I'm getting the following error when I try to run a macro after a combo box updates:

Run-time error '2766':
The object doesn't contain the Automation object '|.'

"cboUpdCust" is a 2 column count combo box.  The condition in the macro is:
[tbl_Customer]![ID]=[Forms]![frm_Main]![cboUpdCust]

I wrote a query using the value from the combo box as a criteria and it worked fine...Example "ID" = 2.  Debug.Print in the Immediate Window also shows that the value is 2.  What gives?
0
error_prone
Asked:
error_prone
  • 3
  • 2
  • 2
1 Solution
 
thenelsonCommented:
Convert the macro to Visual basic. Post the code of the macro and post which line causes the error.
0
 
error_proneAuthor Commented:
I shouldn't have to convert the macro to VB.  Here's what the after update of the combo box does:

Private Sub cboUpdCust_AfterUpdate()
   
    Me.txtCustDisplay.SetFocus
    Me.txtCustDisplay = Me.cboUpdCust & " " & Me.cboUpdCust.Column(1) & " " & Me.cboUpdCust.Column(2)
    DoCmd.RunMacro ("mcr_Upd_Customer")

End Sub

Macro "mcr_Upd_Customer" runs simple action queries with this in the condition section:
[tbl_Customer]![ID]=[Forms]![frm_Main]![cboUpdCust]
0
 
thenelsonCommented:
So which line in the macro is causing the error?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
error_proneAuthor Commented:
The condition in the macro is causing the error.  I took it out and it worked fine.  Is this not the right syntax?  
[tbl_Customer]![ID]=[Forms]![frm_Main]![cboUpdCust]

One of the macro actions this condition is on is a delete query.  So I only want the macro to delete records from tbl_Customer where the ID is equal to the value in cboUpdCust.  I know I can put it in the where clause of the sql statement, but I have multiple queries and I want to re-use objects - that's why I need to use the conditions in a macro.  
0
 
harfangCommented:
The condition column decides whether you run a command or you don't. It will not select records from a table for deletion. Furthermore, when evaluating the condition, there is nothing called "tbl_Customer" accessible. This would be valid only from within a query having "tbl_Customer" in its FROM clause.

You will have to write a query with the condition included, which you can then run directly using DoCmd.RunSQL instead of RunMacro.

(°v°)
0
 
thenelsonCommented:
What action is the condition statement in? What are all the arguments of the action?
0
 
harfangCommented:
Even simpler: delete the customer selected in the combo box...

(°v°)
CurrentDb.Execute "DELETE FROM tbl_Customer WHERE ID=" & cboUpdCust

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now