472,794 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How do I Save Data on Form Only After Button Clicked

1
Hi There

I have a data entry form bound to table , i want to add records only using command button in other words i want to prevent automatic saving while writing into fields .

Thanks
Jan 24 '12 #1

✓ answered by TheSmileyCoder

I disagree dsatino. There is absolutely no need to resort to unbound forms and the headeaches that come with that.


Add a private boolean variable to your form:
Expand|Select|Wrap|Line Numbers
  1. Private bSaveClicked as Boolean
Add code to your command button:
Expand|Select|Wrap|Line Numbers
  1. bSaveClicked=true
  2. On Error Resume Next
  3. Docmd.Runcommand accmdsaverecord
  4. bSaveClicked=false
Add code to your forms beforeupdate:
Expand|Select|Wrap|Line Numbers
  1. If not bSaveClicked Then
  2.   Msgbox "You are trying to navigate away from the active record. Please either save your changes, or press ESC to cancel your changes.",VbOkOnly+vbInformation
  3. Cancel=True
  4. End If

8 19536
dsatino
393 256MB
Then you don't want to bind the bind the form to the table. Just capture the values entered in a sql string and run that on the button click.
Jan 24 '12 #2
TheSmileyCoder
2,322 Expert Mod 2GB
I disagree dsatino. There is absolutely no need to resort to unbound forms and the headeaches that come with that.


Add a private boolean variable to your form:
Expand|Select|Wrap|Line Numbers
  1. Private bSaveClicked as Boolean
Add code to your command button:
Expand|Select|Wrap|Line Numbers
  1. bSaveClicked=true
  2. On Error Resume Next
  3. Docmd.Runcommand accmdsaverecord
  4. bSaveClicked=false
Add code to your forms beforeupdate:
Expand|Select|Wrap|Line Numbers
  1. If not bSaveClicked Then
  2.   Msgbox "You are trying to navigate away from the active record. Please either save your changes, or press ESC to cancel your changes.",VbOkOnly+vbInformation
  3. Cancel=True
  4. End If
Jan 24 '12 #3
NeoPa
32,534 Expert Mod 16PB
I must agree with Smiley here (Sorry Dsatino). The SQL string approach should be avoided where possible, as it is trying to do a job for Access (badly) that Access already does well. Many people seem to see this as a way forward, but I have never seen anything but trouble come from leading people away from the natural way of using Access. It's a bit like using an Object-Oriented computer language, but writing procedural code anyway.

May I just add that this reflects no disrespect towards Dsatino, whom I know to be an accomplished Access expert in various ares. In this case though, we disagree.
Jan 24 '12 #4
dsatino
393 256MB
No disrespect taken. A better way is a better way... :)
Jan 24 '12 #5
NeoPa
32,534 Expert Mod 16PB
A new member, Crobar, posted a request for help with Smiley's code in here so I moved it to a new thread (How Do I Use Code Posted?).
Jan 4 '15 #6
@TheSmileyCoder
Replace "bSaveButtonClicked" with "bSaveClicked"
Jun 6 '17 #7
NeoPa
32,534 Expert Mod 16PB
Good spot :-)
Jun 6 '17 #8
TheSmileyCoder
2,322 Expert Mod 2GB
Thank you. I've fixed the typo. I guess this falls under the category "better late than never"
Jun 13 '17 #9

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

Similar topics

2
by: Rajesh | last post by:
dear all, as of now, am working on a simple access database with a normal data entry form Can I design a form in HTML for data entry, and the same be linked to an access database where the...
2
by: Iain Miller | last post by:
Struggling a bit here & would be grateful for any help. I have a table which has a list of people in it. Each person has a unique ID automatically allocated by Access but also belongs to one of 5...
3
by: intl04 | last post by:
Is it possible to create a Word form as the data entry form for an Access database? I didn't see any reference to this possibility in my Access books, so I'm sorry if this is a question that is...
2
by: edworboys | last post by:
I have designed a data entry form with a number of fields and a sub form. The first field (Country) is a combo box and the user selects a country. This, in turn reduces the number of options in the...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
5
by: Aspnot | last post by:
Background: I have a data entry form that is bound to a DataSet. This DataSet contains 9 tables and the form displays data from each table in textboxes, not a DataGrid. One of the tables in the...
2
by: filbennett | last post by:
Hi Everyone, I'm generally unfamiliar with Access form design, but have programmed Cold Fusion applications for a couple of years. I'd like to build a data entry form in Access that allows the...
2
by: seltzer | last post by:
I am using Access 2000 but I also have the 2003 version. I am working on creating a data entry form in Access for a research study. Since there is a maximum of 255 fields per table in Access, I...
0
by: Tyler | last post by:
Made a data entry form which is a subform. I made a continuous form that displays everything entered through the data entry form. The data entry form displays all of the records. This doesn't...
0
by: Musky09 | last post by:
On a data entry form I am creating the answers to questions 2a1-6 are related to the answer to question 2a...If 2a is "N", questions 2a1-6 are "N/A"...If 2a is "Y", questions 2a1-6 can be "Y", "N",...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.