I copied this Sub (shown below) from a Website and played with it. It spat out a 3265 item not found in this collection, and I could not figure out where caused the trouble.
The procedure will work fine if I remove the line "qdf.Parameters(0) = pstrState". I guess, perhaps that line is not necessary there. But I am wondering why and what causes the error.
"Abbr" is a first field name of the table, it's the state abbreviation.
Phucon
Call RunParameterQuery_DAO (Me!cboState.Column(0))
Public Sub RunParameterQuery_DAO(pstrState As String)
' Comments: Runs a query containing parameters
' Params : pstrState Name of state to select records
Const cstrQueryName As String = "qryUSstates"
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs(cstrQueryName)
qdf.Parameters(0) = pstrState
'Open recordset on the query
Set rst = qdf.OpenRecordset()
Do While Not rst.EOF
Debug.Print ("Abbr: " & rst![Abbr] & " State: " & rst![USState] & " Capital: " & rst![StateCapital])
'Debug.Print Me.cboState.Column(0)
rst.MoveNext
Loop
rst.Close
qdf.Close
dbs.Close
End Sub
Posted by: saigonf7q5@yahoo.com
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (1) |
Tidak ada komentar:
Posting Komentar