Results 1 to 3 of 3

Thread: DOA?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    26
    How do you execute a parmaterized select query with doa and access...i tried this but i guess this is not the correct way: goDatabase.QueryDefs("qryRecipeSEL_ByRecipeID").Parameters("[Recipe ID]") = RecipeID
    goDatabase.Execute ("qryRecipeSEL_ByRecipeID")




  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    For DAO, it's easiest to do this:
    Code:
    Dim rst As Recordset
    Set rst = MyDB.OpenRecordset("SELECT * FROM Recipes WHERE RecipeID = " & lRecipeID, dbOpenSnapshot)
    Simply open up a SQL query as any other recordset.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    ncage - The problem is that the "Execute" method can only be used for "action" queries (INSERT, UPDATE, DELETE, etc.). It CANNOT be used for "SELECT" queries (i.e., queries that will return records). To use SELECT-type Querydef in code (parameterized or not), you must open it into a recordset object. Try this:
    Code:
    Dim qdRecip     As QueryDef
    Dim rsRecip     As Recordset
    
    set qdRecip = goDatabase.QueryDefs("qryRecipeSEL_ByRecipeID")
    qdRecip.Parameters("[Recipe ID]") = RecipeID 
    Set rsRecip = qdRecip.OpenRecordset()
    ' Now rsRecip contains the query results ...
    Do Until rsRecip.EOF
       ' whatever ...
       rsRecip.MoveNext
    Loop
    '...etc...
    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

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



Click Here to Expand Forum to Full Width