开发者

How to create a recordset from SELECT statement (error: Item not found in collection)

I'm trying to open a RecodSet with a SELECT statement but I keep getting this error message: Run-time Error 3265 Item not found in c开发者_如何学Goollection.

I'm running this code on a lostFocus event from a field in a Access 2007 form.

Here's my code:

    Dim myDB As Database
    Dim myREC As DAO.Recordset
    Dim strRegionsMsg, boolRegionMsg
    Dim strQuery
    Set myDB = CurrentDb

    strQuery = "Select * FROM RTA;"
    Set myREC = myDB!Execute(strQuery)
    'Set myREC = myDB!Recordsets(strQuery)

As you cans see, I tried with Recorsets and got the same problem. Also, I ran my query the query builder of Access and it works.

Am I missing something here?


Try this:

Dim myDB As Database
Dim myREC As DAO.Recordset
Dim strRegionsMsg, boolRegionMsg
Dim strQuery
Set myDB = CurrentDb

strQuery = "Select * FROM [RTA]"
Set myREC = myDB.OpenRecordset(strQuery)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜