+ Reply to Thread
Results 1 to 10 of 10

OpenDatabase and Run Query from Excel not working

  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Unhappy OpenDatabase and Run Query from Excel not working

    Hi All,

    I am trying to create VBA in Excel 2003 to open an Access 2003 db, and run a MakeTable Query. I'm not sure if I'm using the wrong vba commands for Excel, or what the problem is- but I can't get my code to work:
    Please Login or Register  to view this content.
    I'm getting a runtime error 424 'Object Required' on the DoCmd line. I thought the database was the object?

    For the record, I don't need the Excel users to see the database, so I'd like to add a visible=false in there somewhere.

    Any help is appreciated, I get completely lost when I try to cross programs in VBA
    Last edited by AnnK; 11-03-2010 at 10:05 AM. Reason: Indicate post has been solved

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: OpenDatabase and Run Query from Excel not working

    Hello AnnK,

    If this macro is being run from Excel then you need to create an object instance of Access before you can use the Access commands, like DoCmd from Excel.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-22-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: OpenDatabase and Run Query from Excel not working

    Thanks Leith (cool name by the way),
    I changed the code to
    Please Login or Register  to view this content.

    Now it's giving me a 'runtime 438- object doesn't support this property or method' on the delete line. I tried removing that line, and I get the 'numeric field overflow' error (as I expected I would if I tried to make a table that was already there). I also get a security message pop-up when it opens the database that I'd like to bypass- but I'll post that separately if I don't find a workaround in the forum.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: OpenDatabase and Run Query from Excel not working

    Hello Annk,

    Glad you like my name. Do you know anyone named Leith?

    I am not an Access programmer and this getting beyond my area of knowledge. I can do a couple of things for you. Because this is more Access centric, I could move this post to the Access forum for you where you may have a better chance of getting an answer faster or refer your post to some of the moderators who have experience with Access or just leave your post here and hope someone will pick it from here. What would you like to do?

  5. #5
    Registered User
    Join Date
    07-22-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: OpenDatabase and Run Query from Excel not working

    No Leiths, just a Lee Our family goes back to the Ayrshire area of Scotland, but we have no interesting names.

    I suppose now that I've gotten the application to launch from Excel, the balance of my questions would probably be better suited to the Access area. So if you could transfer it over that would be great.

    Thanks so much for your help. I have many more Excel jobs ahead- so I'm sure you'll be seeing me back again.

  6. #6
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: OpenDatabase and Run Query from Excel not working

    hi AnnK,

    I'm not an Access wizz either but I've been learning quite a lot in my latest job, so I'll see if I can help...
    (Leith, I hope this doesn't mess up any of your Mod work)

    Here's a couple of UNTESTED changes that may help:
    Please Login or Register  to view this content.
    Re the Security Message:
    Security's normally in place for a reason & some types of discussion are prohibited on this Forum, but if I understand correctly (please provide more detail about the message), I think that setting your "Trusted Locations" may be sufficient. Here's one link which explains Trusted Locations: http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

    hth
    Rob
    Last edited by broro183; 10-27-2010 at 06:00 PM. Reason: add a response about "security message" & remove excessive quote
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  7. #7
    Registered User
    Join Date
    07-22-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: OpenDatabase and Run Query from Excel not working

    Thanks Rob,

    I tried your code, I got the same messages. First I got the 'object required' on the set database line, so I split it out and created an object first like so:
    Please Login or Register  to view this content.
    Which allowed it to continue, then I got the numeric overflow message on open query line again.

    As far as the security message, it is the basic ' if there is malicious code it could harm your computer' message that seems to be Access's version of the load macros warning in Excel (also annoying). I suspect I'm going to have to do something with a digital signature or certificate. I can make it go away for me...but I don't want to have to explain how to go through the same process to everyone at the company. It would be so nice to have a workaround, perhaps MS could make the software smart enough to see that all the files are on a secure network with 8 million safety systems already in place- making their silly message a no-think click through that is not useful for anyone. To my mind- these messages are as helpful as the 'caution- hot' messages on coffee cups. They only help the legal dept.

  8. #8
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: OpenDatabase and Run Query from Excel not working

    I thought I may have made a booboo.

    hmmm...
    What's the exact wording of the "the numeric overflow message on open query line"?
    Have you defined some of the fields in the Table as Integer, and does the query tries to populate them with a value that is greater than +/- 32k?

    Does it work if you go back to the ".Execute "MakeDataTable2010"" version?
    Or if you try any of the other suggestions in this link?

    What's the query's sql string?
    Does it work "manually" if you run it in Access?
    Does it work "manually" if you attempt to use it in Excel via Data - From Access - choose file...?

    LOL, yep they do just seem to be there for the legal dept. How big is your company?
    My office mate & I went through 50ish people to set up their Trusted Locations (in excel, Ppt & Access). It's a hassle but only needs to be done once - unless someone gets a major IT overhaul on their computer.


    Rob
    Last edited by broro183; 10-28-2010 at 03:48 PM.

  9. #9
    Registered User
    Join Date
    07-22-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Smile Re: OpenDatabase and Run Query from Excel not working

    Aha!! I found the problem that was causing the "Numeric Field Overflow" message. I did find that when I ran the query from Access it worked fine, so I did some more searching on the error message. It turns out it is caused by there being mixed data types in the spreadsheet, which when it is linked to Access (which mine is) causes the error upon querying the linked table (but apparently only when the query is initiated from outside of Access). Microsoft provides the solution at

    http://support.microsoft.com/kb/815277

    (I hope it's okay to post a link that is from Microsoft as opposed to a competing board)

    Basically the solution was to run a macro that converts the cells in the mixed columns to text. I already knew that one of my columns was a problem and had done that- but it turns out I had a second column with some entries that were numeric in among the text.

    This also allowed me to lose the line about deleting the table before running the query. I thought that I needed it to address the overflow, but since I fixed the text issue, Access just overwrites the table- so it's unneeded. My final -working- code ends up being
    Please Login or Register  to view this content.
    Thank you for all the help!!
    Last edited by AnnK; 11-03-2010 at 10:06 AM. Reason: spelling error

  10. #10
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: OpenDatabase and Run Query from Excel not working

    hi AnnK,

    Thank you for posting your solution, marking the thread as Solved & giving me some rep'

    Quote Originally Posted by AnnK View Post
    ...
    http://support.microsoft.com/kb/815277

    (I hope it's okay to post a link that is from Microsoft as opposed to a competing board)
    Absolutely!
    If it wasn't for Microsoft, you wouldn't have the application & therefore you wouldn't have the problem - let alone be asking questions on a Forum.
    One of the aims of the Forum is to share knowledge & that's all you're doing
    The rule relating to links to other forums explicitly refers to links "in signatures" & when the rule was published (19/01/2010) I believe the intent was to stop spammers using their signatures as "free advertising". Numerous comments have been made about this Rule, but its implementation still riles me... *counting to ten...*

    So, all I request, is that you continue to share relevant knowledge in posts where you can - whether the solution is from this, or other Forums.

    Rob

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1