Results 1 to 6 of 6
  1. #1
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71

    Error 3061 Too Few parameters

    I have been reviewing through all the previously opened issues for the same error and have tried multiple suggestions in those but have not been able to get this to work for me. Below is a portion of the code that I am working with there the error occurs (isolated it to the Set recParent line). Can someone tell me what is wrong with the SELECT statement?



    Code:
     
    Dim db As DAO.database
    Dim recParent as DAO.Recordset
     
    Set db = CurrentDb
     
    Set recParent = db.OpenRecordset("SELECT * FROM [PPC_Attachments] WHERE [ReqID] = " & Me.[Parent Id])
    Last edited by gopherking; 10-06-2011 at 11:28 AM. Reason: Forgot a line of code ...

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    For consistency with DAO you should say

    Dim db as DAO.Database
    and you must
    Set db = Currentdb

    Also, Parent has a contextual meaning - Parent of the current form-, but I'm not sure that that's the issue here.

  3. #3
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    Sorry Orange, I forgot to add that I do have Set db = Currentdb already in my code. The Dim db as DAO.Database didn't help, still getting the same error. (I'll update my first entry ...)

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If Me.[Parent Id] is a text box containing a string, and if
    [PPC_Attachments].[ReqID] is numeric, you may have an issue.

    You could try

    Dim mStr as string
    mStr = "SELECT * FROM [PPC_Attachments] WHERE [ReqID] = " & Me.[Parent Id]

    The do the
    debug.print mStr to see what's really in the text string.

    What is Me.[Parent id]? And why the spaces in the name?

  5. #5
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    Orange,

    I figured out the problem. I had the wrong field for the SQL to look at (was from another table), once I changed that, it worked with no problems.

    Set recParent = db.OpenRecordset("Select * From PPC_Attachments Where RequestID = " & ParReqID)

    (ParReqID is a variable used for the Me.[Parent ID] field in the code, just didn't include it originally since I couldn't even get it to work with the actual control name)

    As for the Me.[Parent ID], it is a Long Integer field storing the Parent Request ID. The space in there was from some time ago and has been accepted since modifying it would require additional work on old VBA which I am trying not to get into at this time. It is something I have on the roster to clean up from the older code.

    Thanks Orange!

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Glad you got it working.

    A great, but simple, debugging trick is set up your SQL in a string and
    Debug.print thatString to the immediate window.

    You'd be surprised how many times that what's in the string isn't what was suppose to be in the string.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. 3061 Error. Too few parameters. Expected 1.
    By rghollenbeck in forum Queries
    Replies: 5
    Last Post: 09-28-2011, 12:12 PM
  2. Replies: 1
    Last Post: 05-21-2011, 01:33 AM
  3. Error 3061 Too Few Parameters Expecting 1
    By ironman in forum Programming
    Replies: 4
    Last Post: 05-09-2011, 03:20 PM
  4. Error 3061 in VBA program
    By fbou in forum Programming
    Replies: 5
    Last Post: 10-07-2009, 11:00 AM
  5. Error 3061
    By Shanks in forum Queries
    Replies: 4
    Last Post: 09-16-2009, 07:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums