Results 1 to 9 of 9
  1. #1
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421

    Open Select Parameter Query as DATASHEET From VBA?

    This seems like it should be so simple, yet I have not found a solution anywhere. Using VBA, I want to pass 2 parameters to a stored select query and open a datasheet. Using VBA, I can pass parameters to stored action queries, or to sql created in code, or if they are select queries that create recordsets. What I can't figure out is how to pass them to a stored query and open a datasheet. I suppose I could create a continuous form and set its record source to a recordset, but presenting the records in datasheet format is all the user needs. It should be so simple to do. What am I missing?


    Thanks.

  2. #2
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    I have solved my problem without having an answer to the question. I didn't create the database, so I delved into the underlying parameter query to see what was being used by the query I was trying to run from code. Turns out it was only one field, which I could get from the same table as the underlying query. I re-designed the second query's data sources and referenced the form's two textbox controls for the criteria. Docmd.OpenQuery is all that's needed to open a datasheet. Removing the parameters from the underlying query wasn't an option.

    If anyone knows how to pass parameters to a select query and open it in datasheet view from VBA, I'd still love to know.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Users should not interact with tables and queries, only forms and reports.

    I don't use dynamic parameterized queries. I prefer: http://www.allenbrowne.com/ser-62.html

    VBA can modify query objects by manipulating QueryDefs. But I don't recommend this as a routine practice, although I have resorted to in one case.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    I'm aware of the design elements in the link you sent but I still thank you for your input. I'm not sure I see a need to go to those lengths in this case, nor can I dicker with the query def sql since the parameters are in an underlying query. Also, the user is using a form to supply the query criteria in the typical manner used by mostly everyone out there. This means they are interacting with a query, so I'm not sure what you mean by your statement. I think the desired result, how it is used as well as other considerations need to be factors in design. Either the form or datasheet view can present records that are updatable by the user if design limits are not used to prevent such interaction. In my case, the ODBC tables used are read-only, so there is no concern for the type of interaction I think you are referring to. I just wanted a quick and simple method to present non-editable, temporary data for decision making purposes without having to do it in a form. I may end up with one anyway, but if anyone knows how to show parameter query results in datasheet view, I'd still like to know for future reference.
    Thanks.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The OpenQuery method is the only way I know to open a SELECT query object.

    Many developers use code behind forms to manage data integrity so allowing users to interact directly with editable tables and queries could corrupt data. Apparently that is not an issue in your case and seems users are comfortable with viewing records in table/query datasheet.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    One nice thing about a datasheet is the ability to apply a filter or alter the sort by clicking on the header. I've done this in forms, but it's just more coding. I lament the apparent inability to pass parameters to a stored select query and open in datasheet view!

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The header filter/sort can also be utilized in a form or subform set for Datasheet view.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I don't understand what the problem is with passing a literal string to a form's RecordSource and opening the form in DS view.

  9. #9
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Quote Originally Posted by ItsMe View Post
    I don't understand what the problem is with passing a literal string to a form's RecordSource and opening the form in DS view.
    There is no problem except there is no form (yet).

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  2. Replies: 1
    Last Post: 02-28-2013, 01:20 PM
  3. Replies: 8
    Last Post: 08-26-2012, 11:11 PM
  4. use parameter in field name of select query
    By focosi in forum Queries
    Replies: 2
    Last Post: 02-11-2012, 10:34 AM
  5. Parameter Query: Select From A List?
    By catbob in forum Queries
    Replies: 4
    Last Post: 02-08-2010, 08:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums