VBA issue run time error 3061

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aflores41
    New Member
    • Nov 2014
    • 57

    VBA issue run time error 3061

    Hello,

    I need some help troubleshooting the code below. I'm getting a run-time error code 3061, "too few parameters, expected 1". I've searched online (google) but haven't found anything that could help me. Thank you.
    Code:
    Set rst1 = db.OpenRecordset("qry_selected_email_distinct", dbOpenDynaset)
    The code works when the referenced query doesn't have a criteria. I'm using
    Code:
    [TempVars]![username]
    criteria on the query.

    Any help or advise is much appreciated.

    I've confirmed it that the tempvars is causing the code to break. Question is how can I add this code in the vba so the query is filtered by username (tempvars!usern ame)?

    Thank you.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    You can't use tempvars in a query def. However, you can create a SQL string that uses the value inside your Tempvars("UserN ame"). The following assumes that your field name is UserName.
    Code:
    Dim strSQL As String
    
    strSQL = "SELECT * FROM qry_selected_email_distinct WHERE UserName = '" & Tempvars("username") & "'"
    db.OpenRecordset(strSQL, dbOpenDynaset)

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      Well technically you CAN use tempvars in a querydef. The part that is confusing is that it will work when the querydef is used from the Access GUI, i.e. opening the query directly, or binding a form to the same query.

      But trying to access it through the currentdb object, however you can not. For some more information check this msdn answer from Dirk Goldgar:

      Comment

      Working...