|
-
Aug 11th, 2000, 11:51 PM
#1
Thread Starter
Junior Member
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")
-
Aug 12th, 2000, 07:39 AM
#2
Monday Morning Lunatic
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
-
Aug 12th, 2000, 10:57 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|