for Edit and Update what changes are required

venu_resoju

Registered User.
Local time
Today, 23:53
Joined
Dec 29, 2010
Messages
129
Hello all my dear friends,

I have a code for save button, but it is not working for "EDIT" and "UPDATE" the records. what changes are required in the below code for "EDIT"and "UPDATE" options. friends please help me for this.
Private Sub Command87_Click()

Dim db As DAO.Database

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset

Set db = CurrentDb

Set rst1 = db.OpenRecordset("Payroll")

rst1.AddNew

rst1!PayrollID = Me!txtPayrollID
rst1!EmpID = Me!txtEmpID
rst1!EmpName = Me!cboEmpName.Column(1)
rst1!EPFNo = Me!txtEPFNo
rst1!ESINo = Me!txtESINo
rst1!PayPeriod = Me.cbomonth & "-" & Me.cboYear
rst1!WageRate = Me!txtwagerate + Me.txtVDA
rst1!OtherRate = Me!txtOtherRate
rst1!WorkingDays = Me!txtWorkingDays
rst1!NoofDaysWorked = Me!txtNoofDaysWorked
rst1!PH = Me.txtNoofPaidHolidays
rst1!TotalOTHrs = Me!txtOTHrs
rst1!CalcOTHrs = Me.txtcalcOTHrs
rst1!Basic = Me.txtBasic
rst1!PHPay = Me.txtPH
rst1!OTAmount = Me.txtOT
rst1!Medical = Me.txtMedc
rst1!TA = Me.txtTA
rst1!DA = Me.txtDA
rst1!HRA = Me.txtHRA
rst1!Other = Me.txtOtherA
rst1!EPF = Me.txtEPFD
rst1!ESI = Me.txtESID
rst1!CT = Me.txtCT
rst1!Advance = Me.txtAdvance
rst1!OtherDeductions = Me.txtOtherD
rst1!NetPay = Me.txtNetPay
rst1!AdvanceBalance = Me.txtAdvRemaining

rst1.Update
rst1.Close

If Me.txtAdvance > 0 Then
Set rst2 = db.OpenRecordset("LoanTransactions")

rst2.AddNew

rst2!EmpName = Me!cboEmpName.Column(1)
rst2!TransnDate = Date
rst2!TransnType = "Deduction"
rst2!Sanctions = "0"
rst2!Deductions = Me.txtAdvance
rst2!LoanName = "Salary Deduction"
rst2.Update

rst2.Close
Set rst2 = Nothing

End If

Call ClearControls

End Sub

please help me friends, I am learning the access from few days.

Thanking you all
 
A few comments.

Is there a good reason you are not using a bound form for this? It would save a lot of code. The second table could be done in a subform.

I am surprised you are storing the Employee name in the LoanTransaction table. I would have expected the EmployeeID.

I am also inclined to store a numeric code where you use a string "Deduction". You can still display the string via a lookup but it is more efficient to store and query on a number.

It might not especially help here but often numbers are also more useful if you have a series of similar codes. For example all kinds of deductions could be negative numbers. Or you can query numbers in a range.

You also seem to be storing a zero as a string.

And finally, I would suggest you learn about the With Block. It can save a lot of typing.
 

Users who are viewing this thread

Back
Top Bottom