How to change my code for writing a record

venu_resoju

Registered User.
Local time
Tomorrow, 01:08
Joined
Dec 29, 2010
Messages
129
Hai Friends....
I have a form named "PayrollCreation" and have given a code to save button to writing 2no of records as mentioned below...

Private Sub Command87_Click()
On Error GoTo cmdSave_Click_Err


On Error Resume Next

Dim db As DAO.Database

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

Set db = CurrentDb

Set rst1 = db.OpenRecordset("Payroll")
Set rst2 = db.OpenRecordset("LoanTransactions")

rst1.AddNew

rst1!EmpName = Me!cboEmpName.Column(1)
rst1!EPFNo = Me!txtEPFNo
rst1!ESINo = Me!txtESINo
rst1!PayPeriod = Me.cbomonth & "-" & Me.cboYear
rst1!WageRate = Me!txtwagerate
rst1!WorkingDays = Me!txtWorkingDays
rst1!NoofDaysWorked = Me!txtNoofDaysWorked
rst1!Basic = Me.txtBasic
rst1!EPF = Me.txtEPFD
rst1!ESI = Me.txtESID
rst1!NetPay = Me.txtNetPay

rst1.Update
rst1.Close

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

On Error GoTo 0

cmdSave_Click_Exit:
Exit Sub

cmdSave_Click_Err:
MsgBox Error$
Resume cmdSave_Click_Exit

End Sub

the above code is working fine but I want to write the Second record / impliment rst2, I f Me.txtAdvance < 0 else do Nothing. What changes can I do in the above code
Thanks in advance....please anyone help me...
 
Hi

This may be what you are looking for:
Code:
Private Sub Command87_Click()
On Error GoTo cmdSave_Click_Err
 
 
On Error Resume Next
 
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!EmpName = Me!cboEmpName.Column(1)
rst1!EPFNo = Me!txtEPFNo
rst1!ESINo = Me!txtESINo
rst1!PayPeriod = Me.cbomonth & "-" & Me.cboYear
rst1!WageRate = Me!txtwagerate
rst1!WorkingDays = Me!txtWorkingDays
rst1!NoofDaysWorked = Me!txtNoofDaysWorked
rst1!Basic = Me.txtBasic
rst1!EPF = Me.txtEPFD
rst1!ESI = Me.txtESID
rst1!NetPay = Me.txtNetPay
 
rst1.Update
rst1.Close
 
[B]If Me.txtAdvance < 0 Then[/B]
  Set rst2 = db.OpenRecordset("LoanTransactions")
 
  rst2.AddNew
 
  rst2!EmpName = Me!cboEmpName.Column(1)
  rst2!TransnDate = Date
  rst2!TransnType = "Deduction"
  rst2!Sanctions = "0"
  rst2!Deductions = [COLOR=red]Me.txtAdvance[/COLOR]
  rst2!LoanName = "Salary Deduction"
 
  rst2.Update
  rst2.Close
 [B] Set rst2 = Nothing[/B]
[B]End If[/B]
 
On Error GoTo 0
 
cmdSave_Click_Exit:
  [B]Set db = Nothing[/B]
  Exit Sub
 
cmdSave_Click_Err:
  MsgBox Error$
  Resume cmdSave_Click_Exit
 
End Sub
 
Thank you bob fitz...

I have tried like that. In the above code rst1 is working and rst2 is not working. I mean doing nothing.
 
Hi

Is this line correct?
Code:
If Me.txtAdvance < 0 Then
Or should it be
Code:
If Me.txtAdvance [B][COLOR=red]>[/COLOR][/B] 0 Then

What exactly do you mean when you say that rst2 is not working?
 
Hai....

Thank You my dear bob fitz...
Its working when it chenged from Me.txtAdvance<0 to Me.txtAdvance>0

Thank you verymuch......
 

Users who are viewing this thread

Back
Top Bottom