ok so basically, i have a SQL string in a module. When this module is ran, I would like the third recordset to be returned to a query in the database.
I found some code to help me, but it's giving me a type mismatch with the object rs.
- Dim rs As Recordset
-
Dim qdf As QueryDef
-
Dim db As Database
-
-
Set db = CurrentDb
-
Debug.Print IndName
-
Set qdf = db.QueryDefs("Query1")
-
-
qdf.Parameters("Enter Number") = 12 (for now lets sat that 12 is the value being returned from the sql statement)
-
-
'Set rs = qdf.OpenRecordset (this is giving me errors)
I am not exactly sure what you are trying to accomplish, but I do know why you are getting an Error at the OpenRecordset line. When you use the OpenRecordset() Method in conjunction with QueryDef Objects you
must, as a bare minimum, supply the RecordsetType Argument. The Options and LockEdits Arguments are Optional. The following code will now work:
- Dim rs As Recordset
-
Dim qdf As QueryDef
-
Dim db As Database
-
-
Set db = CurrentDb
-
-
Set qdf = db.QueryDefs("Query1")
-
qdf.Parameters("Enter Number") = 9
-
-
Set rs = qdf.OpenRecordset(dbOpenDynaset) 'previous Error
-
rs.MoveLast: rs.MoveFirst
-
-
If rs.RecordCount > 0 Then
-
Do While Not rs.EOF
-
'some Recordset processing
-
Debug.Print rs![LastName]
-
rs.MoveNext
-
Loop
-
End If
-
-
rs.Close