Kamis, 31 Desember 2015

Re: [MS_AccessPros] Error 3265 item not found in this collection

 

Phucon-


What is the SQL of qryUSStates?  If there's no parameter asking for a filter on the state, then that's the problem.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)



On Dec 31, 2015, at 8:49 PM, saigonf7q5@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

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: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

.

__,_._,___

Tidak ada komentar:

Poskan Komentar