Record Change

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wayneyh
    New Member
    • Mar 2008
    • 67

    Record Change

    Hi everyone

    When i open frmSales i have disabled the save button. What i want is if any field on the form is changed the save button is enabled. I can't use OnKey Press as the user might tab through the fields, so it needs to be code. I tried the forms On Data Change but it didn't work.

    Any ideas are appreciated.

    Regards

    Wayne
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    This will Enable the Save button when data is entered/edited:
    Code:
    Private Sub Form_Dirty(Cancel As Integer)
     cmdSave.Enabled = True
    End Sub
    This will reset Enabled to False when moving to a new record
    Code:
    Private Sub Form_Current()
     cmdSave.Enabled = False
    End Sub
    Just replace cmdSave with the actual name of your button.

    Linq ;0)>

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32654

      #3
      As data is saved automatically when navigating to a different record, I don't see what use there would be for a Save CommandButton.

      Were you aware of this?

      Is there any code behind the button other than a simple Save?

      Comment

      • Wayneyh
        New Member
        • Mar 2008
        • 67

        #4
        Thanks again missinglinq

        Much appreciated

        Wayne

        Comment

        • Wayneyh
          New Member
          • Mar 2008
          • 67

          #5
          Yes there is code behind it.

          When they Click save it changes a checkbox to true to and adds the date it was saved. This tells the user that the record needs to be re-printed.
          Code:
          Private Sub btnSave_Click()
          
              DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
              MsgBox "Customer Details for" & " " & Me.Company & " " & "have been saved to the database."
              Me.Changed.Value = True
              Me.BtnClose.Enabled = True
              If Me.Changed.Value = True Then
              Me.ChangedDate = Date
              Me.Printed.Value = False
              Me.Invoice_PrintedDate = ""
              End If
            
          End Sub
          Last edited by NeoPa; Feb 13 '09, 02:57 PM. Reason: Please use the [CODE] tags provided

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32654

            #6
            In that case I suggest you consider ensuring that the record is not saved simply by navigating away from it, as is the normal way of working for a form. Alternatively, use the form's BeforeUpdate() event handler to trigger the same code that is used in your btnSave_Click() procedure.

            The way to do this might be :
            Code:
            Private Sub Form_BeforeUpdate(Cancel As Integer)
              Call CommonCode()
            End Sub
            
            Private Sub btnSave_Click()
              Call CommonCode()
            End Sub
            
            Private Sub CommonCode()
              Blah
              Blah
              Blah
            End Sub
            PS. Please notice the edit comment added to some of your posts about using [ CODE ] tags. This is a requirement. As a full member you would be expected to know the rules by now.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32654

              #7
              Originally posted by NeoPa
              In that case I suggest you consider ensuring that the record is not saved simply by navigating away from it, ...
              I suppose some clarification on this wouldn't hurt either.
              Try something like the following :
              Code:
              Private Sub Form_BeforeUpdate(Cancel As Integer)
                Call MsgBox("Remember to use the Save button (various insulting expletives)!")
                Cancel = True
              End Sub

              Comment

              • Wayneyh
                New Member
                • Mar 2008
                • 67

                #8
                Hi NeoPa

                Thanks for your advice, I will try them out and I apologise for not biding by the rules of the forum.

                Wayne

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32654

                  #9
                  No worries Wayne.

                  I hope the code proves helpful.

                  Comment

                  Working...