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

Save record before it is changed.

Hi All,

I want to save a copy of the record in the main form. If some one changes the record in the main form, how do I save it?

Generally if a female person gets married her title changes from "Miss" to "Mrs" and her surname changes too.

So in this sample database I have tried to save the record on changing of two fields, title and / or surname. It is not working. What am I doing wrong? The record is being saved after the change and not before.

Thanks

Raghu
Attached Files
File Type: zip CopyBeforeUpdate.zip (22.7 KB, 4 views)
May 9 '11 #1
3 1940
Rabbit
12,516 Expert Mod 8TB
Most people aren't going to download attachments. It would be better if you posted the relevant code instead.

Also, I don't know what you mean by saving the record before a change. Are you keeping it in case they want to undo the change? Other than that, I don't really see a reason for it.
May 9 '11 #2
ADezii
8,834 Expert 8TB
I agree with Rabbit, but if you wish to keep a Record of all changes in a Related Table/Sub-Form for the [Title], [Givennames], and [Surname] Fields for the Main Record:
  1. You must add the [ID] Field from Table1 to the Main Form because of the Relationship:
    Expand|Select|Wrap|Line Numbers
    1. Table1.[ID]{1} ==> Table2.[tableID]{MANY}
  2. Create a Private Function in the Code Module of the Main Form:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub CopyRecord()
    2. Dim sSql As String
    3.  
    4. sSql = "INSERT INTO subTable2 ([table1ID], [Title], [GivenNames], [Surname], [DOBirth], [idNumber]) " & _
    5.         "VALUES (" & Me![ID] & ",'" & Me![Title] & "','" & Me![GivenNames] & "','" & Me![Surname] & _
    6.         "',#" & Me![DOBirth] & "#,'" & Me![idNumber] & "');"
    7.  
    8. CurrentDb.Execute sSql, dbFailOnError
    9.  
    10. Me.zfsubTable2.Requery
    11. End Sub
  3. In The BeforeUpdate(0 Event of the three Fields, add the following Code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub GivenNames_BeforeUpdate(Cancel As Integer)
    2.   If Me.NewRecord Then Exit Sub
    3.     Call CopyRecord
    4. End Sub
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Title_BeforeUpdate(Cancel As Integer)
    2.   If Me.NewRecord Then Exit Sub
    3.     Call CopyRecord
    4. End Sub
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Surname_BeforeUpdate(Cancel As Integer)
    2.   If Me.NewRecord Then Exit Sub
    3.     Call CopyRecord
    4. End Sub
  4. Download the Revised Attachment to really see what is going on.
Attached Files
File Type: zip CopyBeforeUpdate_Revised.zip (30.1 KB, 6 views)
May 9 '11 #3
Thanks for the help. It is working like a charm.
May 10 '11 #4

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

Similar topics

4
by: jaYPee | last post by:
anyone know how can i save record from datagrid back to sql server using datacommand? im trying to use dataset but no luck. the source has a join table and when i use the dataadapter wizard it says...
2
by: jaYPee | last post by:
i'm wondering how can i update the current record in datagrid while still editing the record. cause i have a checkbox in my datagrid and i want to save the record before changing the value of this...
2
by: voroojak | last post by:
Hi How can i put save record and next record in one button. in my save record i put the calculation of the text boxes. i have a total field that the sum of the other field is in there and it wil be...
4
by: Trunk3d | last post by:
Hello all. I have a Data Access Page that users can reach to submit a request. At the end of the page I am using a Command Button that is set to Save Record. Is there a way that upon pressing the...
2
by: rockdc1981 | last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the codes work out fine separately. Code for Audit...
1
by: sathyan8294 | last post by:
what is vb.net code for changing the values in datagrid and save the changed values using vb.net windows application
1
by: dkozel | last post by:
I am creating a project that in some areas has many steps to add a record to a database. The binding navigator is great but combined with the some additional steps this gets cumbersome. I would...
8
jmoudy77
by: jmoudy77 | last post by:
Hi, I've got a form that allows a user to imput their flight data. I programmed a MsgBox into the save button that asks if the user wants to input another duty position for the flight. If no, the...
7
by: Neil | last post by:
Was working in A2003 and noticed that the Save Record item on the Records menu was not available when the record was not dirty. In A2000, Save Record was always available. (This is a problem for me...
1
by: Karan Singh Goyal | last post by:
I have an access table which have fields like Customer Id, First Name, Last Name etc. i know how to generate auto number but when i delete last record it generates next number instead of previous one...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.