|
-
Jun 1st, 2007, 11:04 PM
#1
Thread Starter
Junior Member
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
-
Jun 1st, 2007, 11:17 PM
#2
Re: Too Few Parameters, Expected 2
Try printing your sql statement it should be plain as day...
Debug.Print sqlstr
-
Jun 1st, 2007, 11:20 PM
#3
Hyperactive Member
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
If the post is heplful, Please Rate it
Chathura Wijekoon
-
Jun 1st, 2007, 11:21 PM
#4
Thread Starter
Junior Member
Re: Too Few Parameters, Expected 2
thanks for the reply! i appreciate it....how can i do that?honestly im new to visual basic
-
Jun 1st, 2007, 11:23 PM
#5
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.
-
Jun 1st, 2007, 11:26 PM
#6
Thread Starter
Junior Member
Re: Too Few Parameters, Expected 2
can you show it to me by applying it to my code i just posted?please..
-
Jun 1st, 2007, 11:34 PM
#7
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)
-
Jun 1st, 2007, 11:53 PM
#8
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.
-
Jun 1st, 2007, 11:57 PM
#9
Re: Too Few Parameters, Expected 2
 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.
-
Jun 2nd, 2007, 12:09 AM
#10
Thread Starter
Junior Member
Re: Too Few Parameters, Expected 2
tnx but is still doesn't work..
-
Jun 2nd, 2007, 12:13 AM
#11
Thread Starter
Junior Member
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"
-
Jun 2nd, 2007, 12:25 AM
#12
Hyperactive Member
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
-
Jun 2nd, 2007, 12:32 AM
#13
Thread Starter
Junior Member
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)'.
-
Jun 2nd, 2007, 12:35 AM
#14
Thread Starter
Junior Member
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
-
Jun 2nd, 2007, 12:40 AM
#15
Thread Starter
Junior Member
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?
-
Jun 2nd, 2007, 01:52 AM
#16
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.
-
Jun 2nd, 2007, 02:31 AM
#17
Thread Starter
Junior Member
Re: Too Few Parameters, Expected 2
no, i just followed your code that you posted..i just copied and paste it.
-
Jun 2nd, 2007, 02:35 AM
#18
Re: Too Few Parameters, Expected 2
Not even a chance... Post the code with the changes you made.
-
Jun 2nd, 2007, 02:38 AM
#19
Thread Starter
Junior Member
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
-
Jun 2nd, 2007, 02:42 AM
#20
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...
-
Jun 2nd, 2007, 02:50 AM
#21
Thread Starter
Junior Member
Re: Too Few Parameters, Expected 2
sorry..ok i got it..and it prompts this "update profile set password = "2" (int(code)='0'"
-
Jun 2nd, 2007, 02:53 AM
#22
Thread Starter
Junior Member
Re: Too Few Parameters, Expected 2
the password that i entered is "2"
-
Jun 2nd, 2007, 01:07 PM
#23
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.
-
Jun 3rd, 2007, 06:37 PM
#24
Thread Starter
Junior Member
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..
-
Jun 3rd, 2007, 07:40 PM
#25
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...
-
Jun 3rd, 2007, 07:57 PM
#26
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|