Results 1 to 26 of 26

Thread: Too Few Parameters, Expected 2

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Too Few Parameters, Expected 2

    hello guyz..can anybody help me with my problem..i have a command button for update and every time i execute the command, an error occurred "too few parameters, expected 2" how can i solve it? heres my code:


    Private Sub cmdok_Click()
    'On Error Resume Next

    Call openConn

    If Trim(txtnp.Text) = Trim(txtcp.Text) Then
    strsql = "update profile set password='" & Trim(txtnp.Text) & "' where (int(code) = '" & Int(Val(xins_code)) & "') "
    Set myrs = myconn.Execute(strsql, adExecuteNoRecords)
    MsgBox ("Password Updated"), vbOKOnly + vbInformation
    Unload frmchpassword
    frmchpassword.Hide
    Else
    MsgBox ("New-Password and Confirm-Password do not match!"), vbOKOnly + vbCritical
    txtnp.SetFocus
    txtnp = ""
    txtcp = ""
    End If
    Exit Sub
    Call closeConn
    End Sub

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Try printing your sql statement it should be plain as day...

    Debug.Print sqlstr

  3. #3
    Hyperactive Member Chathura's Avatar
    Join Date
    Nov 2005
    Location
    Sri Lanka
    Posts
    345

    Re: Too Few Parameters, Expected 2

    Information you've provided is not enough to guess the problem. If possible put your full code or your project.
    Try
    VB Code:
    1. Private Sub cmdok_Click()
    2.  
    3. Call openConn
    4.  
    5. If Trim(txtnp.Text) = Trim(txtcp.Text) Then
    6.     strsql = "update profile set password='" & Trim(txtnp.Text) & "' where (int[code] = " & Int(Val(xins_code)) & ") "
    7.     myconn.Execute(strsql)
    8.     MsgBox ("Password Updated"), vbOKOnly + vbInformation
    9.     Unload frmchpassword
    10.     frmchpassword.Hide
    11. Else
    12.     MsgBox ("New-Password and Confirm-Password do not match!"), vbOKOnly + vbCritical
    13.     txtnp.SetFocus
    14.     txtnp = ""
    15.     txtcp = ""
    16. End If
    17. Exit Sub
    18. Call closeConn
    19. End Sub
    If the post is heplful, Please Rate it
    Chathura Wijekoon

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    thanks for the reply! i appreciate it....how can i do that?honestly im new to visual basic

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Place that directly after you assign the variable and place a break point on the next line after that in the IDE. Execute your code and look in the immediate window for what it prints. You could also use a msgbox also.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    can you show it to me by applying it to my code i just posted?please..

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Code:
    strsql = "update profile set password='" & Trim(txtnp.Text) & "' where (int(code) = '" & Int(Val(xins_code)) & "')"
    Debug.Print strsql    ' or you can use MsgBox strsql
    Set myrs = myconn.Execute(strsql, adExecuteNoRecords)

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Too Few Parameters, Expected 2

    It looks to me like you are calling the msgbox wrong. Take the () off of it or put the vbokonly stuff on the inside.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Quote Originally Posted by Lord Orwell
    It looks to me like you are calling the msgbox wrong. Take the () off of it or put the vbokonly stuff on the inside.
    No, that's not the problem. That message is from a database query operation.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    tnx but is still doesn't work..

  11. #11

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    i tried the MsgBox strsql and it prompts "false" then an error occurred which says
    "Command text was not set for the command object"

  12. #12
    Hyperactive Member Chathura's Avatar
    Join Date
    Nov 2005
    Location
    Sri Lanka
    Posts
    345

    Re: Too Few Parameters, Expected 2

    Did you try with the code I put in post3 replacing your code?
    If the post is heplful, Please Rate it
    Chathura Wijekoon

  13. #13

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    yes, i already tried it..an error occurred.." [Microsoft][ODBC Microsoft Access Driver] Syntax error(missi ng operator)in query expression'(int[code]=0)'.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    here's my full code to the command button:

    Private Sub cmdok_Click()
    Dim myconn As New ADODB.Connection
    Dim myrs As New ADODB.Recordset
    Dim strsql As String

    On Error Resume Next

    myconn.ConnectionString = "DSN=hrgsmbec"
    myconn.CursorLocation = adUseClient
    myconn.Mode = adModeReadWrite
    myconn.Open

    If Trim(txtnp.Text) = Trim(txtcp.Text) Then
    strsql = "update profile set password='" & Trim(txtnp.Text) & "' where (int(code) = '" & Int(Val(xins_code)) & "') "
    Set myrs = myconn.Execute(strsql, adExecuteNoRecords)
    MsgBox ("Password Updated"), vbOKOnly + vbInformation
    Unload frmchpassword
    frmchpassword.Hide
    Else
    MsgBox ("New-Password and Confirm-Password is Incorrect"), vbOKOnly + vbCritical
    txtnp.SetFocus
    txtnp = ""
    txtcp = ""
    End If
    Exit Sub
    Set myrs = Nothing
    myconn.Close
    Set myconn = Nothing
    End Sub

  15. #15

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    actually, this code is for changing user password..that button is use to update the new entered password..do you have any other suggestions?coz im willing to change my entire code..i just want a code that changes user password..how can i do that?if in case my code doesn't work..can u give me your own codes on how to change user passwords?

  16. #16
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Then you had to have done it wrong.

    Debug.Print strsql

    could not have possibly printed false. Did you place a breakpoint on the very next line? Post what prints.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    no, i just followed your code that you posted..i just copied and paste it.

  18. #18
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Not even a chance... Post the code with the changes you made.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    myconn.ConnectionString = "DSN=hrgsmbec"
    myconn.CursorLocation = adUseClient
    myconn.Mode = adModeReadWrite
    myconn.Open

    If Trim(txtnp.Text) = Trim(txtcp.Text) Then
    MsgBox strsql = "update profile set password='" & Trim(txtnp.Text) & "' where (int(code) = '" & Int(Val(xins_code)) & "') "
    'Debug.Print strsql
    Set myrs = myconn.Execute(strsql, adExecuteNoRecords)
    MsgBox ("Password Updated"), vbOKOnly + vbInformation
    Unload frmchpassword
    frmchpassword.Hide
    Else
    MsgBox ("New-Password and Confirm-Password is Incorrect"), vbOKOnly + vbCritical
    txtnp.SetFocus
    txtnp = ""
    txtcp = ""
    End If
    Exit Sub
    Set myrs = Nothing
    myconn.Close
    Set myconn = Nothing

  20. #20
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    I did not tell you to do this:
    Code:
    MsgBox strsql = "update profile set password='" & Trim(txtnp.Text) & "' where (int(code) = '" & Int(Val(xins_code)) & "') "
    Re-read post #7... Use the original line

    Code:
    strsql = "update profile set password='" & Trim(txtnp.Text) & "' where (int(code) = '" & Int(Val(xins_code)) & "') "
    And when you post code please use the code tags...

  21. #21

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    sorry..ok i got it..and it prompts this "update profile set password = "2" (int(code)='0'"

  22. #22

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    the password that i entered is "2"

  23. #23
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Look at your statement...

    Code:
    update profile set password = "2" (int(code)='0'"
    It is incorrectly formed.

    1 - You have no closing parenthesis
    2 - You have no WHERE clause
    3 - Int(Code) = '0' That makes no sense to compare an integer to a string.
    4 - Double quotes around 2 instead of single quotes.

  24. #24

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    i have a where clause..what i posted earlier is not my code..its the code that prompts on my screen after typing msgbox strsql..

  25. #25
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Too Few Parameters, Expected 2

    Then if that is what strsql has in it YOU DO NOT HAVE A WHERE CLAUSE!!!! Recheck your code... Your copy paste has already been suspect.

    If that is what is in strsql that is what you are attempting to execute...

  26. #26

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Re: Too Few Parameters, Expected 2

    ok.. anyway i solved it already, i made a new code..and it works..anyway, thank you so much for your time..till next time..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width