Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    67

    Unanswered: Open a Recordset Based on a Query

    I thought that opening a Recordset based on a Query was identical to opening a Recordset based on a Table? Apparently not. The below works for Tables in my Database but not for Queries. Any suggestions as to how I can open a Recordset based on my Query named "QryTest"? Here is what I have that gives me an error stating "No value given for one or more required parameters":

    Dim db As DAO.Database
    Dim rs As ADODB.Recordset

    Set rs = New ADODB.Recordset
    rs.ActiveConnection = CurrentProject.Connection

    rs.CursorType = adOpenStatic
    rs.LockType = adLockOptimistic
    rs.CursorLocation = adUseClient

    Set db = CurrentDb

    rs.Open "Select * from QryTest ", Options:=adCmdText


    If I replace "QryTest" in the last line above with the name of a Table, the Table opens with no problems. Any idea as to why I cannot open a Query?

    Thank you for any suggstions.

    Jim

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You are likely running into this type of thing, presuming there are parameters in your query.

    http://support.microsoft.com/default...b;en-us;209203
    Paul

  3. #3
    Join Date
    Feb 2004
    Posts
    67

    Thank you

    Paul,

    Yes, it appears that I am using a "parameter query" without evening knowing what one is!! The Query that I am trying to open is populated via a ListBox on a form. I am trying to run the listbox via VBA code (i.e. simulate a left click of a VBA-selected item) and retrieve the resulting Query, also via VBA code. Sounds like I have my work cut out for me.

    Thanks much for your suggestion. Of course, any other thoughts would be greatly appreciated.

    Jim

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You can't simulate clicking an object and fire it's onclick event. You'll save yourself a whole bunch of headache if you instead place whatever code you're running in a public sub/function.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Feb 2004
    Posts
    67

    Thank you

    Teddy,

    Thanks much for the suggestion. I already have the headache so I am sure you are correct.

    Jim

Posting Permissions

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