Full Version: Simple Query As Recordsource And Persistent 3061 Error
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
seito
Hy guys. I'm pulling my hear out here.

I have couple of queries. Each does some calculations with data and then serves as a source for next.

And final one I need as a recordsource in some VBA code. But I keep getting error 3061: Too few parameters. Expected 1. No matter what I do. First I tried to use saved query simply as a recordsource. Same Error. Then I tried to copy code from saved query directly in to VBA... still same error.

Interesting is, that I can always easily open all queries on their own without any error.

At the moment my part of code that produces error is (SQL from originaly saved query is now in string and used directly in VBA):
CODE
    Dim dbsAnterosHermes As DAO.Database
    Dim rsPosodobiUrnik As DAO.Recordset
    Dim sqlKveri As String
    
    
    Set dbsAnterosHermes = currentDB
    sqlKveri = "SELECT sqlUnionOBISK_URNIK_MOZNOSTI.[DATUM], sqlUnionOBISK_URNIK_MOZNOSTI.[URA], Count(sqlUnionOBISK_URNIK_MOZNOSTI.[URA]) AS [ZasedeniTermini] " & _
                "FROM sqlUnionOBISK_URNIK_MOZNOSTI " & _
                "GROUP BY sqlUnionOBISK_URNIK_MOZNOSTI.[DATUM], sqlUnionOBISK_URNIK_MOZNOSTI.[URA] " & _
                "ORDER BY sqlUnionOBISK_URNIK_MOZNOSTI.[DATUM], sqlUnionOBISK_URNIK_MOZNOSTI.[URA] "
    
    Set rsPosodobiUrnik = dbsAnterosHermes.OpenRecordset(sqlKveri)


Does anybody see any mistake? What could be wrong? Any suggestion, please... I'm going crazy here smile.gif!
darnellk
So you're saying you can open up the Union query on its own without error as well?
MadPiet
not here, but what do the underlying queries look like? Do they have parameters pointing somewhere, like a form?
seito
@darnelk : Exactly. It's making me crazy! And also all Underlying qeries work like a charm.

@ Undelying queries have parameters. But I use tempVars for parameters and also include Or Like .... Is Null in case tempVar is empty. And they work. Each on it's own and all together. If I open them.

One more strange thing. If I doCmd Open query it works and opens as it should. But recordsource, which is directly in next line, still produces error.
darnellk
All I can think of is to substitute each query involved into your .OpenRecordset command so at least you can pin point the problematic query - hopefully there's only one.

Sorry I can't be of more help than that.
seito
Thank you Darnel for fast replay! I played litlle bit more and now it seams that code goes through...

Obviously problem was in some string that were then used on this recordsource and I didn't Dim ... As String them!

Now I have compile error on some following code, but that's another story.
seito
To post a solution if anybody will get in same problems.

Problem was (and still is) in use of TempVars. They work fine with queries but are not supported when you want use that query as recordset. There are couple workarounds.

One is to create function with tempVars and another is to create dummy form and then assign this recordset to it.

http://blogs.office.com/b/microsoft-access...nrecordset.aspx

I'm going with the last one. Stupid exceptions....
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.