PDA

View Full Version : Getting run time error 3265 (Item not found in collection)



anandks42
06-26-2008, 08:54 AM
Hi,
I am trying to modify an existing query def(qryExample) I created previously.

Function ChangeQDef(ByVal strQuery As String, ByVal strSQL As String) As Boolean
Dim qdf As QueryDef
Dim boolResultCode As Boolean

If (strSQL = "") Or (strQuery = "") Then
boolResultCode = False
Else
MsgBox ("I am here")
'On Error Resume Next
Set qdf = CurrentDb.QueryDefs("strQuery")
If Err.Number <> 0 Then
boolResultCode = False
Else
qdf.SQL = strSQL
qdf.Close
RefreshDatabaseWindow
boolResultCode = True
End If
On Error GoTo 0
End If

ChangeQDef = boolResultCode

End Function

I am running it in the immediate window like this:
?ChangeQDef("qryExample", "SELECT * FROM tblCompany ORDER BY Company Name")

tblCompany exists and Company Name is a field in that table. Please help me as I don't know why I am getting this error. Thanks!

OBP
06-26-2008, 09:28 AM
Try
?ChangeQDef("qryExample", "SELECT * FROM tblCompany ORDER BY [Company Name]")
or
?ChangeQDef("qryExample", "SELECT * FROM tblCompany ORDER BY Company_Name")

anandks42
06-26-2008, 10:27 AM
Hi,

The reason it did not work because strquery was passed as "strquery" in the code. Thanks.