Save, msg to changes, refresh

venu_resoju

Registered User.
Local time
Today, 23:51
Joined
Dec 29, 2010
Messages
129
Hai..Friends..

I have a save button problem, but I didn't get solution till now, I have tried again and again.
I have a from with a 'save' button which have given some code like mentioned below. I want to do 3 things by clicking "Save" button which are...
1) Save/write record in given table path
2) Refresh all fields of the form
3) If already saved the same record , want to show msgbox with 'Yes','No' and 'Cancel'
(masbox is not showing and not refreshing all fields)

Please help me......

Code:
Private Sub Command87_Click()
On Error GoTo cmdSave_Click_Err

    On Error Resume Next
    
If IsNull(cboEmpName) Then
MsgBox "Please Select Employee Name"
Me.cboEmpName.SetFocus
End If

If Me.txtNoofDaysWorked.Value = "0" Then
MsgBox "Please Enter No of Worked Days"
End If


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
    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 - (Me.txtNoofPaidHolidays * Me.txtwagerate)
    rst1!phpay = Me.txtNoofPaidHolidays * Me.txtwagerate
    
             
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

'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNoCancel, "Changes Made...") = vbYes Then
DoCmd.Save
MsgBox "Record has been saved"
DoCmd.GoToRecord , , acNewRec
Else
Cancel = True
End If

  On Error GoTo 0
    
cmdSave_Click_Exit:
Set db = Nothing
    Exit Sub

Me.cboEmpName.Value = ""

cmdSave_Click_Err:
    MsgBox Error$
    Resume cmdSave_Click_Exit
    
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom