Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    Too few parameters. Expected 1

    I have a Navigation form with a few tabs on it. The first tab is open to a blank form, when the second tab is selected the form in the first tab is blank and creates an empty row in my table.

    To avoid this I added a datacheck to remove the blank rows but I'm getting an error...

    Too few parameters. Expected 1 when I wrote this:

    Code:
    If IsNull(Me.txtProjectNumber) Then
         Set rs = db.OpenRecordset("SELECT RequestID FROM tbl_Req WHERE txtProjectNumber is Null
       While Not rs.EOF
    rs.Delete
    rs.MoveNext
    Wend
    Set rs =Nothing
    End If
    Exit Sub
    Too few parameters. Expected 2 when I changed it to this:

    Code:
    If IsNull(Me.txtProjectNumber) Then
         Set rs = db.OpenRecordset("SELECT RequestID FROM tbl_Req WHERE Me.txtProjectNumber is Null
       While Not rs.EOF
    rs.Delete
    rs.MoveNext
    Wend
    Set rs =Nothing
    End If
    Exit Sub
    Any ideas?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,281
    Concatenate the control value.
    Query has no clue about form controls unless you specify the full form name and control.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Not sure how you mean. I added
    Code:
    WHERE [Forms]![frmReq]![txtProjectNumber] is Null
    but still Expecting 2 parameters

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    You need to isolate the variable txtProjectNumber:
    Code:
    Set rs = db.OpenRecordset("SELECT * FROM tbl_Req WHERE " & Me.txtProjectNumber & " is Null;",dbOpenDynaset) 'if txtProjectNumber is numeric
    Set rs = db.OpenRecordset("SELECT * FROM tbl_Req WHERE '" & Me.txtProjectNumber & "' is Null;",dbOpenDynaset) 'if txtProjectNumber is text
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Thank you!

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    You're welcome!
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    I keep getting the same error even though I followed your instructions

    Quote Originally Posted by Gicu View Post
    You're welcome!

    This is a different sql in the same form

    Code:
     tmpRS = CurrentDb.OpenRecordset("SELECT tbl_PPISD.FPNUMBER, tbl_PPISD.ISD FROM tbl_PPISD" & _
                                                                " WHERE tbl_PPISD.[FPNumber] = ' " & Me.txtProjectNumber & " ' ;", dbOpenDynaset)
    What am I doing wrong?

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,281
    Leaving spaces with the single quote
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Quote Originally Posted by Welshgasman View Post
    Leaving spaces with the single quote
    Thanks for responding, I was praying someone did! this is the entire code, but it's still expecting a parameter even after I removed the spaces


    Code:
            Set db = CurrentDb
            Debug.Print
            tmpRS = db.OpenRecordset("SELECT * FROM tbl_PP_ISD_ WHERE tbl_PP_ISD_.[FPNumber] = '" & Me.txtProjectNumber & "' ;", dbOpenDynaset)
                If tmpRS.RecordCount > 0 Then
                    Me.txtPPISD = rs.Fields(0)
                Else
                    Me.txtPPISD = 0
                End If
            Set tmpRS = Nothing

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,281
    So put the select into string variable debug.print it, the copy that to a query sql window and run it and see what happens.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Quote Originally Posted by Welshgasman View Post
    So put the select into string variable debug.print it, the copy that to a query sql window and run it and see what happens.
    In the immediate window I get the correct sql that I need

    Select * from tbl_PPISD Where tbl_PPISD.[FPNumber] = '99115'

    Which is what I want

  12. #12
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    So as mentioned, you copy the immediate window output into a new query in sql view. Then switch to datasheet view (I'd advise to not run action queries, use datasheet view instead). If it doesn't balk and shows a datasheet, the sql is good. Don't worry if the datasheet is blank. Usually, fields with "number" in the name are numbers, not text, so there's that. If it's a text field, keep the single quotes. If not, ditch them. There are ways to fix this error message if the aforementioned approaches don't work.

    EDIT - might help to show more of the code before what you have. You can often resolve the problem by assigning the value of a form control to a variable and use the variable instead of the control reference in the sql. Otherwise, you might have to declare Parameter(s).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Quote Originally Posted by Micron View Post
    So as mentioned, you copy the immediate window output into a new query in sql view. Then switch to datasheet view (I'd advise to not run action queries, use datasheet view instead). If it doesn't balk and shows a datasheet, the sql is good. Don't worry if the datasheet is blank. Usually, fields with "number" in the name are numbers, not text, so there's that. If it's a text field, keep the single quotes. If not, ditch them. There are ways to fix this error message if the aforementioned approaches don't work.

    EDIT - might help to show more of the code before what you have. You can often resolve the problem by assigning the value of a form control to a variable and use the variable instead of the control reference in the sql. Otherwise, you might have to declare Parameter(s).
    I tried the following to no avail:

    Code:
    strSQL= "select * from tbl_PPISD where tbl_PPISD.[FPNumber] = " & Me.txtProjectNumber & "'""
    Set rs = db.OpenRecordset(strSQLc)
    and even though the debugging print returns the correct result, I'm still missing a parameter.

  14. #14
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Try
    Dim strProject As String, strSql As String

    strProject = Me.txtProjectNumber
    strSql = "select * from tbl_PPISD where tbl_PPISD.[FPNumber] = '" & strProject & "'"

    That's one of the potential solutions I referred to. Make sure you have not mis-spelled a field or control name, otherwise you'll get the error message forever.
    When I said post more code I had something much more revealing in mind
    Got to be honest - when suggestions are made and not followed (paste/datasheet view) and seemingly not addressed it makes it harder to keep an old guy's attention for long.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,281
    Quote Originally Posted by carmenv323 View Post
    I tried the following to no avail:

    Code:
    strSQL= "select * from tbl_PPISD where tbl_PPISD.[FPNumber] = " & Me.txtProjectNumber & "'""
    Set rs = db.OpenRecordset(strSQLc)
    and even though the debugging print returns the correct result, I'm still missing a parameter.
    Paste it into a sql window and see what Access complains about.?
    If your parameter is correct, it will likely be the fieldname at fault?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Too few parameters. Expected 1.
    By smith.jr in forum Programming
    Replies: 4
    Last Post: 08-06-2019, 07:23 PM
  2. Too few parameters. Expected 1.
    By SierraJuliet in forum Programming
    Replies: 17
    Last Post: 02-01-2019, 02:28 PM
  3. Too Few Parameters Expected 9
    By RunTime91 in forum Access
    Replies: 11
    Last Post: 05-31-2018, 07:10 PM
  4. too few parameters; expected 2
    By slimjen in forum Forms
    Replies: 13
    Last Post: 07-26-2012, 02:42 PM
  5. Too few parameters. expected 1.
    By seth1685 in forum Programming
    Replies: 1
    Last Post: 01-11-2012, 08:08 AM

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