By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

Record Change

P: 67
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.


Feb 13 '09 #1
Share this Question
Share on Google+
8 Replies

Expert 2.5K+
P: 3,532
This will Enable the Save button when data is entered/edited:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Dirty(Cancel As Integer)
  2.  cmdSave.Enabled = True
  3. End Sub
This will reset Enabled to False when moving to a new record
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  cmdSave.Enabled = False
  3. End Sub
Just replace cmdSave with the actual name of your button.

Linq ;0)>
Feb 13 '09 #2

Expert Mod 15k+
P: 31,419
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?
Feb 13 '09 #3

P: 67
Thanks again missinglinq

Much appreciated

Feb 13 '09 #4

P: 67
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSave_Click()
  3.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  4.     MsgBox "Customer Details for" & " " & Me.Company & " " & "have been saved to the database."
  5.     Me.Changed.Value = True
  6.     Me.BtnClose.Enabled = True
  7.     If Me.Changed.Value = True Then
  8.     Me.ChangedDate = Date
  9.     Me.Printed.Value = False
  10.     Me.Invoice_PrintedDate = ""
  11.     End If
  13. End Sub
Feb 13 '09 #5

Expert Mod 15k+
P: 31,419
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 :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   Call CommonCode()
  3. End Sub
  5. Private Sub btnSave_Click()
  6.   Call CommonCode()
  7. End Sub
  9. Private Sub CommonCode()
  10.   Blah
  11.   Blah
  12.   Blah
  13. 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.
Feb 13 '09 #6

Expert Mod 15k+
P: 31,419
I suppose some clarification on this wouldn't hurt either.
Try something like the following :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   Call MsgBox("Remember to use the Save button (various insulting expletives)!")
  3.   Cancel = True
  4. End Sub
Feb 13 '09 #7

P: 67
Hi NeoPa

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

Feb 13 '09 #8

Expert Mod 15k+
P: 31,419
No worries Wayne.

I hope the code proves helpful.
Feb 13 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.