?
Solved

MS Access - The object doesn't contain the automation object... Run time error 2766

Posted on 2008-11-15
13
Medium Priority
?
4,813 Views
Last Modified: 2013-11-27
I have an Access 2000 format database that contains the VBA code

OtherContract = DLookup("[Contract Code]", "TimeSheets", "[Contract Code] <> [frmqryTimeSheets]![Contract Code] AND [Payroll Number] = [frmqryTimeSheets]![Payroll Number] AND [Worked Week No] = [frmqryTimeSheets]![Worked Week No] AND [Sun] > 0 ")

When the database is accessed with Access 2007 I get a run time error 2766 and the message "The object doesn't contain the automation object frmqryTimesheets".  The same code run from a machine running Office XP works perfectly, and it has previously worked perfectly from the Office 2007 machines.  I am not aware of any changes that have been made to the PCs involved.

Can anyone explain why this is happening?   Many thanks in advance.
0
Comment
Question by:dedwardsa
  • 7
  • 6
13 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 22966712
I don't really see how the code could have ever worked. The syntax is incorrect.
You need...

OtherContract = DLookup("[Contract Code]", "TimeSheets", "[Contract Code] <>" &  [frmqryTimeSheets]![Contract Code] & " AND [Payroll Number] =" &  [frmqryTimeSheets]![Payroll Number] & " AND [Worked Week No] = " & [frmqryTimeSheets]![Worked Week No] & " AND [Sun] > 0 ")
0
 

Author Comment

by:dedwardsa
ID: 22984218
Thanks, but there must be something else at work..  

I have copied and pasted your corrected query and now get an error 2465, access can't find the field "|" in your query.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 22984646
Correction:

othercontract = DLookup("[Contract Code]", "TimeSheets", "[Contract Code] <>" & Forms!frmqryTimeSheets![Contract Code] & " AND [Payroll Number] =" & Forms!frmqryTimeSheets![Payroll Number] & " AND [Worked Week No] = " & Forms!frmqryTimeSheets![Worked Week No] & " AND [Sun] > 0 ")
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:dedwardsa
ID: 22984807
I know this is going to sound really ungrateful, but  - that generates error 2450, access can't find the form frmqryTimeSheets  refered to in the macro or VBA...

Sorry, and thanks!
0
 
LVL 77

Expert Comment

by:peter57r
ID: 22984912
Is the form open?
0
 

Author Comment

by:dedwardsa
ID: 22984979
Yes...
0
 
LVL 77

Expert Comment

by:peter57r
ID: 22985210
Then it can't be called frmqrytimesheets.

What name appears in the objects list?

If you compile the application does it report errors?
0
 

Author Comment

by:dedwardsa
ID: 22985404
But it is.  frmqryTimeSheets in the object list, bold as brass.  

As I said, the syntactically incorrect code works fine under XP, it's just 2007 that's giving me grief (which is sad as we've just u/graded all round)...

Thanks again.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 22985743
'code works fine under XP'

I'm sorry to have to be so blunt but that is utterly impossible.
The code is fundamentally wrong and would be absolutely certain to produce an error message.
(Probably one that said ' You cancelled the previous operation').

The only explanations for you not getting such an error is that this bit of code was never used or you have error messages suppressed..

There are lots of issues being seen with conversion of docs/apps into Office 2007 and I am at a loss to understand why companies are doing such upgrades without testing first.
But we need to see what can be done about your specific problem.

Open frmqrytimesheets to an existing record.

Go into the Immediate window in VBA and try:
?DLookup("[Contract Code]", "TimeSheets", "[Contract Code] =" & Forms!frmqryTimeSheets![Contract Code] )

(This assumes that Contract code is a number)
It should return the same value to you as is shown in the form.

0
 

Author Comment

by:dedwardsa
ID: 22986556
Fair comments.  

Anyway, you're not going to like this...

2450, can't find frmqrytimesheets...
0
 
LVL 77

Accepted Solution

by:
peter57r earned 1500 total points
ID: 22986852
Hey ho...

How about..(open the form first)
?forms!frmqrytimesheets.name

If there's still a problem, open another form and try its name in the command.

I think we're heading for creating a new blank database and importing everything into it...but just try the above first.
0
 

Author Comment

by:dedwardsa
ID: 23027071
Thanks for the help, I will get back to this in a day or two.   I've gone back to XP to get things rolling for the time being.
0
 

Author Closing Comment

by:dedwardsa
ID: 31517064
Thanks for the help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question