473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How Do I Use Code Posted?

2
Hello TheSmileyCoder. <Fingers crossed that this thread isn't tool old :) > I am trying to implement your recommended solution for this problem, but I do not know where to paste the code. I'm using Access 2013. How do I perform this?

Thank you!

<Mod Edit NeoPa>
This has been moved into a new question thread as hijacking threads is not allowed.
The thread it came from is How do I Save Data on Form Only After Button Clicked.
Jan 3 '15 #1
3 2339
twinnyfo
3,653 Expert Mod 2GB
Crobar,

Insert the declaration at the top of your form, before any Subs or Functions.

The next block of code is added to the OnClick event of your Save Button (you must have a Save Button to use the code).

The third block of code is added to the Form's BeforeUpdate Event. Your code on the form should look something like this:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private bSaveClicked as Boolean
  5.  
  6. Private Sub Form_BeforeUpdate(Cancel As Integer)
  7.     If Not bSaveClicked Then
  8.         MsgBox "You are trying to navigate away from the " & _
  9.             "active record. Please either save your " & _
  10.             "changes, or press ESC to cancel your changes.", _
  11.             VbOkOnly + vbInformation
  12.         Cancel=True
  13.     End If
  14. End Sub
  15. Private Sub cmdSave_Click()
  16.     bSaveClicked=True
  17.     On Error Resume Next
  18.     Docmd.Runcommand acCmdSaveRecord
  19.     bSaveClicked=False
  20. End Sub
Thanks to Smiley for the code (I did change the name of the Class variable to match the rest of the code). NB: I did not include any error handling, which I always recommend for every sub and function.

Hope this hepps!
Jan 5 '15 #2
Crobar
2
Hi twinnyfo,

Thank you for the reply. The part I am confused about is what is meant by "top of the form"?. If I'm looking at the form in design view, where would this code go?

I'm an Access newb, learning from Google as I go.

Thanks again!
Jan 10 '15 #3
twinnyfo
3,653 Expert Mod 2GB
I mis-spoke. It should be at the top of the VBA module behind your form. Clicking the "Code" button when the form is in design view will open the VBA module for that Form.

I hope this helps!
Jan 10 '15 #4

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

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
29
by: Gernot Frisch | last post by:
Hi, I have no clue. - I want to align the red, green, blue boxes in one line - red,green,blue must be 45px high - red (center) must be as wide as possible - yellow must start exactly below...
9
by: scriptguru | last post by:
I've found some funny pieces of code in one project... I don't know: to laught or to cry =) function toHex(decimal) { switch(decimal) { case 10: return "A"; case 11: return "B"; case 12:
5
by: CDMAPoster | last post by:
I have changed how I get the shell path for Acrobat Reader based on code posted by John deKrafft. Does anyone see any problems with this code running on various Windows OS's? '--Begin Module...
8
by: anju07 | last post by:
hi, I am using the following javascript code to compare 2 dates, one of which is sysdate and the other is the date from my text field in my jsp. function rbvalidation(ctl) { var cal = new...
2
by: AccessCoder | last post by:
What is the proper way to reference code snippets that are copied from usenet group examples? What about when a developer posts code that is copyrighted and they allow you to use it in a...
9
by: nixonmg | last post by:
When the Command Button "Notify" is clicked, I am wanting to send out an email to the user with appropriate information in the email (works great), check the "Notified" check box (does not work), and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.