Results 1 to 8 of 8
  1. #1
    venu_resoju is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    19

    how to give a code for save and refresh

    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......



    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

    End Sub


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Are you using bound form to enter/edit data? Why code to create record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    venu_resoju is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    19

    How to Code for Save button to Save data, Msg for Rewrite and Refresh form after save

    I am here with attaching my mdb file.

    I am trying to code for "save" button on "PayrollCreationByMonthlyAttendance" form to save/write data, asking msg for rewrite if already exist and refresh form after saving data.but I couldn't get it.please help me how can I solve.

    Thanking you....
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Let me rephrase my question: Why are you appending to recordset with VBA?

    Record is committed to table when form closes, move to another record, or run code (DoCmd.RunCommand acCmdSaveRecord).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    venu_resoju is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    19
    I have some calculated fields which automatically get the calculated results when select a "EmpName" Combobox on the form, like "=txtBasic*txtWageRare"

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    That doesn't explain why you are using recordset in VBA to add record.

    That calculated data should not be saved to table and even if you really want to a recordset is not needed to save data of the current record of the form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    venu_resoju is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    19
    Thank you June7,

    Please explain how can I use the bound form with having those formulas in text boxes of the form.
    I want to learn from you...Please explain me with using my mdb.

    Thanking you

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I answered my question. You are using recordset code because the form is not bound. Bind the form and Payroll recordset code is not needed.

    Me!PayPeriod = Me.cbomonth & "-" & Me.cboYear
    Me!Basic = Me.txtBasic - (Me.txtNoofPaidHolidays * Me.txtwagerate)
    Me!PHPay = Me.txtNoofPaidHolidays * Me.txtwagerate
    DoCmd.RunCommand acCmdSaveRecord

    Should not save employee name, only employee ID. Set EmpID field in Employee table as primary key.

    The LoanTransaction recordset code should be okay.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Refresh Table Links Code
    By Lowell in forum Programming
    Replies: 5
    Last Post: 03-05-2013, 11:16 PM
  2. Form Code refresh on open
    By mseeker22 in forum Forms
    Replies: 2
    Last Post: 07-08-2011, 12:35 AM
  3. Replies: 3
    Last Post: 10-04-2010, 01:31 PM
  4. Don't want to save forms on Refresh or closing
    By accesscoder in forum Forms
    Replies: 5
    Last Post: 09-25-2010, 12:03 AM
  5. Help With Save Data Code
    By ColPat in forum Programming
    Replies: 5
    Last Post: 06-07-2010, 12:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums