+ Reply to Thread
Results 1 to 22 of 22

Use ADO with Parameters

  1. #1
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Use ADO with Parameters

    I want to use ADO to pull a query into a spreadsheet. The problem I have is --- is it possible to pass parameters to that query via VBA? For example, with this query, It asks for a begin date and an end date. The begin date of course is Last Sunday, the end date is Saturday (02-26-2012 ---- 03-03-2012) Is there a way for me to pass those dates via ADO?

    EDIT --- let me also add that the dates of course change, but the range is always from Sunday to Saturday.
    Last edited by jo15765; 03-05-2012 at 11:08 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    Yep. It might be better to post what you have so far. I'm assuming this is a stored procedure in something like SQL server?

  3. #3
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Use ADO with Parameters

    It's an access query, I can post the SQL for the access query, or would you rather see the VBA from Excel?

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    Both please

  5. #5
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Use ADO with Parameters

    Please Login or Register  to view this content.
    Let me know if you need anything further
    Last edited by jo15765; 03-05-2012 at 11:23 AM. Reason: Forgot Code Tags

  6. #6
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Use ADO with Parameters

    For an Access query, I would actually recommend DAO instead.
    Good luck.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    Yeah, DAO would be better, perhaps you can adapt OnError?

    I've rewritten snb's code, for ADO, something like:
    Please Login or Register  to view this content.
    You'll notice that I've printed the SQL string to the immediate window, you should copy and paste this into Access just to make sure it's the correct syntax

    you'll need to set a reference to Microsoft ActiveX Data Objects

    As an aside, I would say that your database needs a re-think, have a look at relational database design and normalization
    Last edited by Kyle123; 03-05-2012 at 11:37 AM.

  8. #8
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Use ADO with Parameters

    Hmmm...Thank you for the response. I will look into the Database Design and Normalization. The more I think about it, I am running the same query from in multiple databases (because the data is being pulled from different tables). It would almost be more feasible to me, to just run a Union Query so that way I am only entering one database, and running one query, as opposed to many.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    I am running the same query from in multiple databases (because the data is being pulled from different tables)
    Do you mean that you have the same table layout in multiple tables in one database, or the same table layout in multiple tables in multiple databases?

    This seems very wrong. For example, you shouldn't be repeating customer details address etc for multiple orders. You should have at the very least, a customers table and an orders table. The Primary Key in the customers table should be a foreign key in the orders table. Depending on your data, you may also want further tables for state etc.

    The reason for this: If a customer's name changes/address changes, you only need to update the customers table once and this will cascade through, in your current format you would need to update the customer multiple times - this would be a nightmare. In addition how would you handle multiple contacts from the same customer - this may/may not be an issue depending on what you are doing.

    Hope this helps

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    Thanks Rory

  11. #11
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Use ADO with Parameters

    Oh I completely agree, the structure and layout is atrocious! The primary key that is assigned in each database is an auto number field, so the primary key really doesn't benefit the table either. I am taking this over from someone else who had it set up this way.. The set-up of this is SOOOO flawed, and I am trying to combine as much as possible. The status quo is there are multiple databases, with multiple tables, each containing orders, and customer info. Why? I have NO idea, but they are bound to multiple reports/forms that I haven't had the time to decipher through yet. So I was currently just running the query from each individual database (hence I made the Union Query). Another for the moment fix, I was thinking about doing was just creating a table in the databases, and just running a append query from each databases to the table I made so that way I am querying ONE table.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    haha sounds like fun

  13. #13
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Use ADO with Parameters

    Wherever I've worked, I've often thought that much of the complexity and illogical structure of End-User Computing applications was down to the incumbent ensuring his/her own job security. A little knowledge is a dangerous thing.

    I know I'm guilty of that too

  14. #14
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Use ADO with Parameters

    Quote Originally Posted by Firefly2012 View Post
    Wherever I've worked, I've often thought that much of the complexity and illogical structure of End-User Computing applications was down to the incumbent ensuring his/her own job security. A little knowledge is a dangerous thing.
    IME, 80% of it is down to the complexity and illogical structure of End-Users...

  15. #15
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Use ADO with Parameters

    Quote Originally Posted by Firefly2012 View Post
    I know I'm guilty of that too
    I've often time's complained about a programmer or contractor over-complicating a system, so that you have to consistently use them for add-ons, mod's etc. In this instance, I pray that it wasn't a programmer trying to over complicate things, it more-so looks to me like it was someone who didn't have a clue what they were doing.

  16. #16
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Use ADO with Parameters

    Quote Originally Posted by OnErrorGoto0 View Post
    IME, 80% of it is down to the complexity and illogical structure of End-Users...
    Stoopidity might play a significant part too - oh, and the need to hang around on web forums answering questions rather than doing work Hmm, let me see, that error goes away if I put On Error Resume Next at the top of the routine...


  17. #17
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    haha anything like this? http://thc.org/root/phun/unmaintain.html

  18. #18
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Use ADO with Parameters

    Quote Originally Posted by Kyle123 View Post
    That website is hilarious!!! OMG, I am passing along to all my programmer co-workers!

  19. #19
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Use ADO with Parameters

    Access Denied for me Damn workplace...

  20. #20
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Use ADO with Parameters

    Yeah I can't get on it either, but I remember reading it. It's brilliant, even worth reading at home

  21. #21
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Use ADO with Parameters

    Quote Originally Posted by Kyle123 View Post
    That is a masterpiece. I plan to spend tomorrow bedazzling the names of all my variables... (well, that and learning LDAP queries in .Net )

  22. #22
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Use ADO with Parameters

    I will spend my afternoon doing this:
    Dummy Interfaces
    Write an empty interface called something like "WrittenByMe", and make all of your classes implement it. Then, write wrapper classes for any of Java's built-in classes that you use. The idea is to make sure that every single object in your program implements this interface. Finally, write all methods so that both their arguments and return types are WrittenByMe. This makes it nearly impossible to figure out what some methods do, and introduces all sorts of entertaining casting requirements. For a further extension, have each team member have his/her own personal interface (e.g., WrittenByJoe); any class worked on by a programmer gets to implement his/her interface. You can then arbitrary refer to objects by any one of a large number of meaningless interfaces!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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