Excel 2010 VBA Code in Access

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.

Suggestions?
pmpataneAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
change this line

DoCmd.OpenQuery "qryDeleteAR", acViewNormal, acEdit

with

oapp.DoCmd.OpenQuery "qryDeleteAR", acViewNormal, acEdit
0
 
pmpataneAuthor Commented:
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!
0
 
Rey Obrero (Capricorn1)Commented:
check the db where you wrote the code, look for query "De2Cust"..
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.

All Courses

From novice to tech pro — start learning today.