Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim bid As Integer
Private Sub cboBid_Click()
Dim rs2 As New ADODB.Recordset
bid = Val(cboBid.Text)
rs2.Open "SELECT * FROM Book_info where Book_id= " & bid & " ", con, adOpenKeyset, adLockOptimistic
rs2.MoveFirst
While (rs2.EOF <> True)
If (rs2(0) = bid) Then
txtBookname.Text = (rs2("Bookname"))
txtDis.Text = (rs2("Discount"))
txtSp.Text = (rs2("Sellingprice"))
rs2.MoveNext
End If
Wend
rs2.Close
End Sub
Private Sub cmdAdd_Click()
enablerec
clearrec
MsgBox "You can add new record", vbOKOnly + vbInformation
'txtBillno.Text = (rs("Bill_no")) + 1
txtCName.SetFocus
End Sub
Private Sub cmdCal_Click()
txtTotal.Text = Val(txtSp.Text) * Val(txtQuantity.Text)
End Sub
Private Sub cmdCancel_Click()
clearrec
End Sub
Private Sub cmdExit_Click()
Dim p As String
p = MsgBox(" Do you want to exit? ", vbYesNo + vbInformation)
If p = vbYes Then
Unload Me
frmMdi.Show
Else
frmBill.Show
End If
End Sub
Private Sub cmdSave_Click()
'Dim rs4 As New ADODB.Recordset
'rs1.Open "SELECT * FROM Sales where Book_id=' " & cboBid.Text & " '", con, adOpenDynamic, adLockPessimistic
'Set res5 = New ADODB.Record
rs1.AddNew
rs1("Sales_date") = DTPicker1.Value
rs1("Sales_id") = txtSalesid.Text
rs1("C_name") = txtCName.Text
rs1("Book_id") = cboBid.Text
rs1("Total") = txtTotal.Text
rs1.Update
rs1.Close
'Dim rs3 As New ADODB.Recordset
'rs.Open "SELECT * FROM Book_info where Book_id= " & cboBid.Text & " ", con, adOpenDynamic, adLockPessimistic
'Set res1 = New ADODB.Recordset
rs.AddNew
rs("Book_id") = cboBid.Text
rs("Bookname") = txtBookname.Text
rs("Discount") = txtDis.Text
rs("Sellingprice") = txtSp.Text
rs("Quantity") = txtQuantity.Text
rs.Update
MsgBox "Record is saved", vbOKOnly + vbInformation
rs.Close
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open App.Path & "\Bookshop.mdb"
rs.ActiveConnection = con
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Open "SELECT * FROM Book_info"
Set rs1 = New ADODB.Recordset
rs1.ActiveConnection = con
rs1.CursorLocation = adUseClient
rs1.CursorType = adOpenDynamic
rs1.LockType = adLockOptimistic
rs1.Open "SELECT * FROM Sales"
End Sub
Private Sub enablerec()
txtSalesid.Locked = False
txtCName.Locked = False
cboBid.Locked = False
txtBookname.Locked = False
txtDis.Locked = False
txtSp.Locked = False
txtQuantity.Locked = False
txtTotal.Locked = False
End Sub
Private Sub clearrec()
txtSalesid.Text = ""
txtCName.Text = ""
cboBid.Text = ""
txtBookname.Text = ""
txtDis.Text = ""
txtSp.Text = ""
txtQuantity.Text = ""
txtTotal.Text = ""
End Sub
i am able to save data into the database but when i press save button it shows errors but the data i wont save is going to the database...............i am a bit confused plz help!.....i am using Vb 6.0 ans Ms access 2007
i am highlighting statements where errors occur.....
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim bid As Integer
Private Sub cboBid_Click()
Dim rs2 As New ADODB.Recordset
bid = Val(cboBid.Text)
rs2.Open "SELECT * FROM Book_info where Book_id= " & bid & " ", con, adOpenKeyset, adLockOptimistic
rs2.MoveFirst
While (rs2.EOF <> True)
If (rs2(0) = bid) Then
txtBookname.Text = (rs2("Bookname"))
txtDis.Text = (rs2("Discount"))
txtSp.Text = (rs2("Sellingprice"))
rs2.MoveNext
End If
Wend
rs2.Close
End Sub
Private Sub cmdAdd_Click()
enablerec
clearrec
MsgBox "You can add new record", vbOKOnly + vbInformation
'txtBillno.Text = (rs("Bill_no")) + 1
txtCName.SetFocus
End Sub
Private Sub cmdCal_Click()
txtTotal.Text = Val(txtSp.Text) * Val(txtQuantity.Text)
End Sub
Private Sub cmdCancel_Click()
clearrec
End Sub
Private Sub cmdExit_Click()
Dim p As String
p = MsgBox(" Do you want to exit? ", vbYesNo + vbInformation)
If p = vbYes Then
Unload Me
frmMdi.Show
Else
frmBill.Show
End If
End Sub
Private Sub cmdSave_Click()
'Dim rs4 As New ADODB.Recordset
'rs1.Open "SELECT * FROM Sales where Book_id=' " & cboBid.Text & " '", con, adOpenDynamic, adLockPessimistic
'Set res5 = New ADODB.Record
rs1.AddNew
rs1("Sales_date") = DTPicker1.Value
rs1("Sales_id") = txtSalesid.Text
rs1("C_name") = txtCName.Text
rs1("Book_id") = cboBid.Text
rs1("Total") = txtTotal.Text
rs1.Update
rs1.Close
'Dim rs3 As New ADODB.Recordset
'rs.Open "SELECT * FROM Book_info where Book_id= " & cboBid.Text & " ", con, adOpenDynamic, adLockPessimistic
'Set res1 = New ADODB.Recordset
rs.AddNew
rs("Book_id") = cboBid.Text
rs("Bookname") = txtBookname.Text
rs("Discount") = txtDis.Text
rs("Sellingprice") = txtSp.Text
rs("Quantity") = txtQuantity.Text
rs.Update
MsgBox "Record is saved", vbOKOnly + vbInformation
rs.Close
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open App.Path & "\Bookshop.mdb"
rs.ActiveConnection = con
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Open "SELECT * FROM Book_info"
Set rs1 = New ADODB.Recordset
rs1.ActiveConnection = con
rs1.CursorLocation = adUseClient
rs1.CursorType = adOpenDynamic
rs1.LockType = adLockOptimistic
rs1.Open "SELECT * FROM Sales"
End Sub
Private Sub enablerec()
txtSalesid.Locked = False
txtCName.Locked = False
cboBid.Locked = False
txtBookname.Locked = False
txtDis.Locked = False
txtSp.Locked = False
txtQuantity.Locked = False
txtTotal.Locked = False
End Sub
Private Sub clearrec()
txtSalesid.Text = ""
txtCName.Text = ""
cboBid.Text = ""
txtBookname.Text = ""
txtDis.Text = ""
txtSp.Text = ""
txtQuantity.Text = ""
txtTotal.Text = ""
End Sub
i am able to save data into the database but when i press save button it shows errors but the data i wont save is going to the database...............i am a bit confused plz help!.....i am using Vb 6.0 ans Ms access 2007
i am highlighting statements where errors occur.....