Excel 2010 VBA Code in Access

Posted on 2012-08-31
Medium Priority
Last Modified: 2012-08-31
I am baffled beyond belief here.  I have the following code to run a delete query in Access which works perfectly:
    Set oapp = CreateObject("Access.Application")
    oapp.Visible = True
    oapp.OpenCurrentDatabase "C:\Desktop\Module 1.accdb"

    DoCmd.OpenQuery "De2Cust", acViewNormal, acEdit

Open in new window

Yet this code returns with error 424 Object required
    Set oapp = CreateObject("Access.Application")
    oapp.Visible = True
    oapp.OpenCurrentDatabase "C:\Desktop\Database5.accdb"

    DoCmd.OpenQuery "qryDeleteAR", acViewNormal, acEdit

Open in new window

I copied and pasted the query name from Access to the VBA in Excel to make sure there was no typo.  I can't figure out why this is happening.

Question by:pmpatane
  • 2
LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 2000 total points
ID: 38354955
change this line

DoCmd.OpenQuery "qryDeleteAR", acViewNormal, acEdit


oapp.DoCmd.OpenQuery "qryDeleteAR", acViewNormal, acEdit

Author Closing Comment

ID: 38355473
Works perfectly!  But here's the tricky part...why does the first code I posted work without the oapp before the DoCmd, yet all others don't?  Just my curiosity.

Thanks for very quick solution you gave!
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38355672
check the db where you wrote the code, look for query "De2Cust"..

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

840 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