Results 1 to 9 of 9
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Recordset Too few parameters expected 1

    I'm trying to open a recordset to loop through and apply payments. I'm getting the too few parameter error at the bold red line below. The query runs fine on its own. Thanks in advance.




    Code:
    Private Sub Command52_Click()
        DoCmd.SetWarnings False
     
        Dim strsql As String
        Dim BD As Variant
        Dim BL As Variant
        Dim CR As Variant
        Dim db As Variant
        Dim tb As Variant
        Dim P As Variant
        Dim mbrid As Integer
        Dim dp As Date
        Dim cn As Variant
        Dim dbs As Database
        Dim rst As Recordset
        Dim rssql As String
     
        dp = DatePaid
        mbrid = Me.MemberID
        BD = Me.baldue
        BL = Me.balleft
        CR = Me.CRAmount
        db = Me.DBAmount
        tb = Me.totalbal
        P = Me.payment
        cn = Me.CheckNum
        rssql = "SELECT [dbamount]-Nz([cramount],0) AS baldue, Accounts.DBAmount, Accounts.CRAmount, Accounts.AsmtType, Accounts.Details, Accounts.LotNumber, Accounts.EnteredBy, Accounts.DatePaid, Accounts.CheckNumber, Accounts.Note " & vbCrLf & _
    "FROM Accounts " & vbCrLf & _
    "WHERE (((Accounts.MemberID)=[Forms]![AccountsandPayments]![MemberID])) " & vbCrLf & _
    "ORDER BY Accounts.DateAssessed;"
     
     
        'Add to payments
        strsql = "INSERT INTO AsmtPayments (PaymentAmount, MemberID, PaymentDate,checknum )"
        strsql = strsql & " VALUES (" & P & ", " & mbrid & "," & cn & ", #" & dp & "#);"
        CurrentDb.Execute strsql, dbFailOnError
     
     
        DoCmd.SetWarnings True
        Requery
     
     
        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset(rssql, dbOpenDynaset) 
    
    etc...etc...

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    you don't need the

    & vbCrLf &

    when building a sql string

    but I think the reason for your error is this

    "WHERE (((Accounts.MemberID)=[Forms]![AccountsandPayments]![MemberID])) "

    should be

    "WHERE (((Accounts.MemberID)=" & [Forms]![AccountsandPayments]![MemberID] & ")) "

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,130
    You have the values and field names in a different order in strsql statement so Access can't use them
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  4. #4
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thanks Ridders, I caught that and rearranged as necessary. :-)

  5. #5
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I am now getting a syntax error. "Syntax error in insert into statement." When I debug, the values are correct.
    Code:
    Private Sub Command52_Click()
        DoCmd.SetWarnings False
        Dim strsql As String
        Dim BD As Variant
        Dim BL As Variant
        Dim CR As Variant
        Dim db As Variant
        Dim tb As Variant
        Dim P As Variant
        Dim mbrid As Integer
        Dim dp As Date
        Dim pd As Date
        Dim cn As Variant
        Dim dbs As Database
        Dim rst As Recordset
        Dim rssql As String
        
        
        dp = DatePaid
        mbrid = Me.MemberID
        BD = Me.baldue
        BL = Me.balleft
        CR = Me.CRAmount
        db = Me.DBAmount
        tb = Me.totalbal
        P = Me.payment
        cn = Me.CheckNum
        
        
    'set the recordset sql
    rssql = "SELECT Accounts.DBAmount, Accounts.CRAmount, Accounts.DateAssessed, Accounts.AsmtType, Accounts.Details, Accounts.LotNumber, Accounts.EnteredBy, Accounts.DatePaid, Accounts.CheckNumber " & vbCrLf & _
    "FROM Accounts " & vbCrLf & _
    "WHERE (((Accounts.MemberID)=" & [Forms]![AccountsandPayments]![MemberID] & ")) "
    Debug.Print rssql
    
        'Add to payments
        strsql = "INSERT INTO AsmtPayments (PaymentAmount, MemberID, PaymentDate, checknum )"
        strsql = strsql & "  VALUES (" & P & ", " & mbrid & ", #" & dp & "#," & cn & ""
        
    CurrentDb.Execute strsql, dbFailOnError (Errors here)
        DoCmd.SetWarnings True
        Requery
    
    etc etc
    Correct Debug Results:
    P = 94.07
    mbrid = 1
    dp = 4/6/2018
    cn = 57

    Additional information: The payment, date paid and check number are collected from unbound fields on the subform. Don't know if this matters or not. If I attempt to run an append query using the data in the unbound fields I get greek characters "긔葺䁗" in payment amount but it does append correctly to the asmt payments table.

    I know I've been looking at this for too long. TIA.

  6. #6
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Not sure what I did, messed around with quotes and stuff, and no longer getting an error.

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,374
    you are missing the ending bracket
    strsql = strsql & " VALUES (" & P & ", " & mbrid & ", #" & dp & "#," & cn & "" )

    Tip for the future: output sql to immediate window before executing. That way, all variables are 'converted'. Copy/paste to new query and switch to datasheet view (so that if it's all good, and it's an action query, the query doesn't actually run). If there are any syntax issues, most of the time Access will highlight them when you attempt to switch views.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thanks Micron! I'll give it a shot!

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,374
    Enjoy! I should have said all variables are converted IF reference correctly. Goes for control references too.

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

Similar Threads

  1. Too Few Parameters. Expected 1
    By flamesofdoom in forum Programming
    Replies: 1
    Last Post: 02-15-2013, 02:23 PM
  2. too few parameters; expected 2
    By slimjen in forum Forms
    Replies: 13
    Last Post: 07-26-2012, 02:42 PM
  3. Too few parameters. expected 1.
    By seth1685 in forum Programming
    Replies: 1
    Last Post: 01-11-2012, 08:08 AM
  4. Too few parameters expected 4
    By forestgump in forum Programming
    Replies: 1
    Last Post: 04-15-2011, 09:10 AM
  5. Too few parameters. Expected 2.
    By PPCMIS2009 in forum Access
    Replies: 0
    Last Post: 01-28-2009, 01:02 PM

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