Excel 2010 VBA Code in Access

Posted on 2012-08-31
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
    LVL 119

    Accepted Solution

    change this line

    DoCmd.OpenQuery "qryDeleteAR", acViewNormal, acEdit


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

    Author Closing Comment

    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 119

    Expert Comment

    by:Rey Obrero
    check the db where you wrote the code, look for query "De2Cust"..

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
    This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
    This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now