954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

About Updating a Record in adodb

Private Sub Command1_Click()
If Combo1.Text = "" Then
MsgBox "Please Choose Supplier Code", vbInformation
Combo1.SetFocus
Exit Sub
End If
If Combo2.Text = "" Then
MsgBox "Please Choose Product Code", vbInformation
Combo2.SetFocus
Exit Sub
End If
If Text1.Text = "" Then
MsgBox "Please Input the Quantity", vbInformation
Text1.SetFocus
Exit Sub
End If
If Text3.Text = "" Then
MsgBox "Please Input the Amount", vbInformation
Text3.SetFocus
Exit Sub
End If
rs.Open "Insert Into Deliver (scode, pcode, quantity, unit, amount, pcarrier, pterms, drnumber, date) Values ('" + Combo1.Text + "','" + Combo2.Text + "','" + Text1.Text + "','" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text5.Text + "','" + Text6.Text + "','" + Text7.Text + "')", cn, adOpenKeyset, adLockPessimistic
Set rs = Nothing
rs1.Open "select * from Product where pcode='" & Combo2.Text & "'", cn, adOpenKeyset, adLockPessimistic
If rs1.RecordCount > 0 Then
rs1.Fields![pstock] = Val(rs1.Fields![pstock]) + Val(Text1.Text)
rs1.Update
rs.Close
MsgBox "The Product has been save successfully", vbInformation
Combo1.Text = ""
Combo2.Text = ""
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Call Form_Load
Else
MsgBox "OHH NO!", vbInformation
End If
End Sub

i have a problem everytime i click my command1 button can anyone help me about my problem? please? badly needed rush! please help me god bless daniweb!


error is on about in INSERT INTO

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

Corrections

rs.Open "Insert Into Deliver (scode, pcode, quantity, unit, amount, pcarrier, pterms, drnumber, date) Values ('" + Combo1.Text + "','" + Combo2.Text + "','" + Text1.Text + "','" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text5.Text + "','" + Text6.Text + "','" + Text7.Text + "')", cn, adOpenKeyset, adLockPessimistic


must be

cn.Execute "Insert Into Deliver (scode, pcode, quantity, unit, amount, pcarrier, pterms, drnumber, date) Values ('" + Combo1.Text + "','" + Combo2.Text + "','" + Text1.Text + "','" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text5.Text + "','" + Text6.Text + "','" + Text7.Text + "')"

and

rs1.Open "select * from Product where pcode='" & Combo2.Text & "'", cn, adOpenKeyset, adLockPessimistic


must be

rs1.Open "select * from Product where pcode='" & Combo2.Text & "'", cn, adOpenDynamic, adLockOptimistic


remove the statement
[code[
rs.close[/code]

Regards
Shaik Akthar

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

still have a synthax error :(

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

in the insert into

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

check out the syntax. u have added single quotes to the numeric fields also. remove them.

'" + Combo1.Text + "','" + Combo2.Text + "','" + Text1.Text + "','" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text5.Text + "','" + Text6.Text + "','" + Text7.Text + "'
'must be
'" + Combo1.Text + "','" + Combo2.Text + "'," + Text1.Text + "," + Text2.Text + "," + Text3.Text + "," + Text4.Text + "," + Text5.Text + "," + Text6.Text + "," + Text7.Text + ")"


I am unable to figure out the numeric fields from ur query, but that's the problem.

Put quotes for text fields and remove them for numeric fields.


Regards
Shaik Akthar

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

huhuhu sir still an error ocured in insert into

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

post the code again now,

and which of ur fields are Text and which of them are numeric in the database

and also the error message please.

Regards
Shaik Akthar

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

wrong number of agruments thats is the eror!

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

post the code again now,

and which of ur fields are Text and which of them are numeric in the database

and also the error message please.

Regards
Shaik Akthar

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

If Combo1.Text = "" Then
MsgBox "Please Choose Supplier Code"
Combo1.SetFocus
Exit Sub
End If
If Combo2.Text = "" Then
MsgBox "Please Choose Product Code"
Combo2.SetFocus
Exit Sub
End If
If Text1.Text = "" Then
MsgBox "Please Input the Quantity"
Text1.SetFocus
Exit Sub
End If
If Text3.Text = "" Then
MsgBox "Please Input the Amount"
Text3.SetFocus
Exit Sub
End If
cn.Execute "Insert Into Deliver (scode, pcode, quantity, unit, amount, pcarrier, pterms, drnumber, date) Values ('" + Combo1.Text + "','" + Combo2.Text + "'," + Text1.Text + "," + Text2.Text + "," + Text3.Text + "," + Text4.Text + "," + Text5.Text + "," + Text6.Text + "," + Text7.Text + ")", cn, adOpenKeyset, adLockPessimistic
rs1.Open "select * from Product where pcode='" & Combo2.Text & "'", cn, adOpenDynamic, adLockOptimistic
If rs1.RecordCount > 0 Then
rs1.Fields![pstock] = Val(rs1.Fields![pstock]) + Val(Text1.Text)
rs1.Update
rs1.Close
MsgBox "The Product has been save successfully", vbInformation
Combo1.Text = ""
Combo2.Text = ""
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Call Form_Load
Else
MsgBox "OHH NO!", vbInformation
End If

Compile Error:

wrong Number of agruments or invalid property assignment

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

ur code is

"Insert Into Deliver (scode, pcode, quantity, unit, amount, pcarrier, pterms, drnumber, date) Values ('" + Combo1.Text + "','" + Combo2.Text + "'," + Text1.Text + "," + Text2.Text + "," + Text3.Text + "," + Text4.Text + "," + Text5.Text + "," + Text6.Text + "," + Text7.Text + ")"


I assume scode, pcode, unit, pcarrier, pterms, drnumber, date are Text fields
and quantity, amount are Numeric fields
hence

"Insert Into Deliver (scode, pcode, quantity, unit, amount, pcarrier, pterms, drnumber, date) Values ('" + Combo1.Text + "','" + Combo2.Text + "'," + Text1.Text + ",'" + Text2.Text + "'," + Text3.Text + ",'" + Text4.Text + "','" + Text5.Text + "','" + Text6.Text + "','" + Text7.Text + "')"


also remove the
, cn, adOpenKeyset, adLockPessimistic
in the insert statement.

Regards
Shaik Akthar

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

syntax error in inert into

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

what is the datatype of the field 'date' in your database and is it MS-Access Database?

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

just once give me all the fields with their datatypes with which they exist in the database in the table Deliver

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

the date is Date/time and the rest is text

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

If the database is MS-Access u have to use a # for date field.
It goes like this. replace the query with this one.

"Insert Into Deliver (scode, pcode, quantity, unit, amount, pcarrier, pterms, drnumber, date) Values ('" + Combo1.Text + "','" + Combo2.Text + "'," + Text1.Text + ",'" + Text2.Text + "'," + Text3.Text + ",'" + Text4.Text + "','" + Text5.Text + "','" + Text6.Text + "',#" + Text7.Text + "#)"
aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

still having a error

synthax error in insert into, how can i upload my files here? can u fix it?

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

just zip the access database file and the vbform.

Click on Reply to Thread button. do not post in quick reply.
below the reply box u can find the button for attachments. there u select the zip file and upload it.

aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

i have enclosed a screenshot of the reply screen

Attachments abc1.bmp (338.04KB)
aktharshaik
Posting Whiz
316 posts since Aug 2008
Reputation Points: 26
Solved Threads: 40
 

here it is!

Attachments Inventory_System.zip (46.42KB)
ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You