-
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
-
Re: Too Few Parameters, Expected 2
Try printing your sql statement it should be plain as day...
Debug.Print sqlstr
-
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:
Private Sub cmdok_Click()
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)) & ") "
myconn.Execute(strsql)
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
-
Re: Too Few Parameters, Expected 2
thanks for the reply! i appreciate it....how can i do that?honestly im new to visual basic
-
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.
-
Re: Too Few Parameters, Expected 2
can you show it to me by applying it to my code i just posted?please..
-
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)
-
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.
-
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.
-
Re: Too Few Parameters, Expected 2
tnx but is still doesn't work..:cry:
-
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"
-
Re: Too Few Parameters, Expected 2
Did you try with the code I put in post3 replacing your code?
-
Re: Too Few Parameters, Expected 2
yes, i already tried it..an error occurred.." [Microsoft][ODBC Microsoft Access Driver] Syntax error(missi:cry: ng operator)in query expression'(int[code]=0)'.
-
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
-
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?
-
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.
-
Re: Too Few Parameters, Expected 2
no, i just followed your code that you posted..i just copied and paste it.
-
Re: Too Few Parameters, Expected 2
Not even a chance... Post the code with the changes you made.
-
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
-
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...
-
Re: Too Few Parameters, Expected 2
sorry..ok i got it..and it prompts this "update profile set password = "2" (int(code)='0'"
-
Re: Too Few Parameters, Expected 2
the password that i entered is "2"
-
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.
-
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..
-
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...
-
Re: Too Few Parameters, Expected 2
ok..:D anyway i solved it already, i made a new code..and it works..anyway, thank you so much for your time..till next time..:wave: :wave: