PDA

Click to See Complete Forum and Search --> : DOA?


ncage
Aug 11th, 2000, 11:51 PM
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")

parksie
Aug 12th, 2000, 07:39 AM
For DAO, it's easiest to do this:

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.

BruceG
Aug 12th, 2000, 10:57 AM
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:

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...