473,320 Members | 1,828 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,320 software developers and data experts.

what is the save command code in ms access?

hello guys im a beginner in programming .. i have a problem in saving option in access... in access when you type information in fields it automatically save in database if you click the next button command even if you are not clicking the save button..
and i want is, the data will not be save if the save button command is not using..

(sorry for the grammar english is not my first language)

hope you understand my point .. thank you :)
Jun 14 '18 #1

✓ answered by NeoPa

Hi Emmannuelle.

There are two parts to this question :
  1. What code is used to save a record?
  2. How do I ensure it only saves when I use the save code, and not simply when the operator moves to another record?

For #1 I have a routine as the code itself is such that it doesn't look like it's going to save the record.
Expand|Select|Wrap|Line Numbers
  1. 'SaveRec() Saves the current record on frmMe.
  2. Public Sub SaveRec(frmMe As Form)
  3.     'No error handling here.  Should be handled by calling code if required.
  4.     'This code is a little weird but how saving has been implemented in Access.
  5.     frmMe.Dirty = False
  6. End Sub
This is part of a standard module that can be called by the code from any Form.

For #2 we use a variable that is only set to allow saves from the part of our code where we want the saves to succeed. The variable is set as Private in the Form's code module. In the BeforeUpdate() Event handler code you use the Cancel parameter if that variable isn't set, so the save fails.
Expand|Select|Wrap|Line Numbers
  1. Private blnAllowSave As Boolean
  2. ...
  3. Private Sub Form_BeforeUpdate(Cancel As Integer)
  4.     If Not blnAllowSave Then
  5.         Cancel = True
  6.         Call MsgBox(Prompt:="Please use the Save Button to save your changes." _
  7.                   , Buttons:=VbOKOnly Or VbInformation _
  8.                   , Title:=Me.Name)
  9.     End If
  10. End Sub
  11. ...
  12. Private Sub cmdSave_Click()
  13.     blnAllowSave = True
  14.     Call SaveRec(frmMe:=Me)
  15.     blnAllowSave = False
  16. End Sub

9 3076
NeoPa
32,556 Expert Mod 16PB
Hi Emmannuelle.

There are two parts to this question :
  1. What code is used to save a record?
  2. How do I ensure it only saves when I use the save code, and not simply when the operator moves to another record?

For #1 I have a routine as the code itself is such that it doesn't look like it's going to save the record.
Expand|Select|Wrap|Line Numbers
  1. 'SaveRec() Saves the current record on frmMe.
  2. Public Sub SaveRec(frmMe As Form)
  3.     'No error handling here.  Should be handled by calling code if required.
  4.     'This code is a little weird but how saving has been implemented in Access.
  5.     frmMe.Dirty = False
  6. End Sub
This is part of a standard module that can be called by the code from any Form.

For #2 we use a variable that is only set to allow saves from the part of our code where we want the saves to succeed. The variable is set as Private in the Form's code module. In the BeforeUpdate() Event handler code you use the Cancel parameter if that variable isn't set, so the save fails.
Expand|Select|Wrap|Line Numbers
  1. Private blnAllowSave As Boolean
  2. ...
  3. Private Sub Form_BeforeUpdate(Cancel As Integer)
  4.     If Not blnAllowSave Then
  5.         Cancel = True
  6.         Call MsgBox(Prompt:="Please use the Save Button to save your changes." _
  7.                   , Buttons:=VbOKOnly Or VbInformation _
  8.                   , Title:=Me.Name)
  9.     End If
  10. End Sub
  11. ...
  12. Private Sub cmdSave_Click()
  13.     blnAllowSave = True
  14.     Call SaveRec(frmMe:=Me)
  15.     blnAllowSave = False
  16. End Sub
Jun 14 '18 #2
thank you sir NeoPa i will try it sir.. ill post here if it works
thanks a lot :D
Jun 14 '18 #3
sir NeoPa your 2nd code really did work .. but im having a problem in the save code...


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdsave_Click()
  2.   Public Sub SaveRec (frmMe As Form)
  3. frmMe.Dirty = False
  4.  
  5. End Sub
  6. End Sub
  7.  
  8.  
  9.  
thats where the error is ... i think i write it wrong in the code
Jun 14 '18 #4
twinnyfo
3,653 Expert Mod 2GB
emmannuelle15,

First, you should do a direct copy and paste of the code provided by NeoPa. It is clear from your last post that this did not happen.

When you think of a procedure, think of it as a distinct unit of code. Anything between the Private Sub [NameOfProcedure]() and End Sub statements are autonomous and can't have anything inside except what belongs specifically to that procedure.

For your preivous post remove lines 1 and 6 to start. You must also have the second portion of NeoPa's code in your form's VBA module. It should work "as is", using your command button.

Hope this hepps.
Jun 14 '18 #5
NeoPa
32,556 Expert Mod 16PB
Indeed. Use Copy/Paste (Recommended) or, if that's not possible because your names are different, at least Copy/Paste first, and then change only those names you need to.

If you can simply copy visually then fine, but you need to be able to do it 100% reliably if you do. Why bother though, when using Copy/Paste is both easier and more reliable?
Jun 14 '18 #6
sir twinnyfo and sir NeoPa thank you for the advice i really appreciate it.. ill keep it in mind :D
Jun 19 '18 #7
twinnyfo
3,653 Expert Mod 2GB
Were we able to resolve your primary issue?
Jun 19 '18 #8
yes sir :D thank you
Jun 20 '18 #9
NeoPa
32,556 Expert Mod 16PB
Good to see. This is a helpful thread as many need help with exactly that.
Jun 20 '18 #10

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

Similar topics

0
by: Danny | last post by:
Hello Thanks for your help with the text box being grayed out. I can't see the post to say thanks, I hope you read this. (how in Outlook express can you see all the newsgroup posts?) I am...
1
by: Cillies | last post by:
Hello all, I was recently browsing the forum and remembered seeing a message relating to MS Access Bugs/Flaws. The thing is I cannot find that thread anymore, and so was wondering does anyone know...
4
by: tt40 | last post by:
Anyone know how to prevent Access 2002 from automatically breaking all the incorrect joins in a query and then automatically saving the broken query? This is what I would call stupid design...
0
by: namanhvu | last post by:
I've installed MySQL v4.1 onto my WinXP and unfortunately now need to reinstall my OS. I need to access my mysql command line history but don't know how. I know there's a .mysql_history file but...
2
by: accessjunior | last post by:
I was wondering if there is any way to close Access using command line swithes? Currently I have a batch file that calls the .mdb runs a macro and compacts, then I would like to close it. Any...
1
by: mcVBNet10 | last post by:
I am working on a project in VB.Net using access as backend. But I wanted to take advantage of access reporting power. Therefore I was trying to see if I could open an Access Report (Built inside of...
1
by: Bob Alston | last post by:
Trying to install some software on Access 2007. The software works just fine on earlier versions of Access. I have been told that it works on Access 2007 but I have not seen that personally. ...
2
by: dstork | last post by:
Anyone know how to rename the "Exit Access" command at the bottom of the Office menu. I'd like to rename it to "Exit" as I had done in previous versions of Access. I know I can disable it with ...
1
by: MiziaQ | last post by:
I'm trying to save fixed length data into a random access file. Right now it works, but saves everything in one, continuous line. How can save every new entry in a new line. Also, I want to...
3
by: OASys1 | last post by:
Hello ... I have an Access 2007 app, and I need a routine to export all table data, and then import this table data into a new version of my compiled stand alone executable Access app. I came...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.