473,651 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tracking Data Changes on Form

52 New Member
I'm trying to track data changes on my database. On form I create a procedure on Before Update event to track data changes, here it is: (It also puts the username who changes the record.

Dim ctl As Control
For Each ctl In Controls

If TypeOf ctl Is TextBox Then
If ctl.Value <> ctl.OldValue Then

Dim ans As Integer
ans = MsgBox("A record has changed." & vbcrkf + vbCrLf & _
"Do you want to save the record.", vbYesNo)
If ans = vbYes Then
Me.txtUpdatedBy .Value = fOSUserName
DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
Cancel = True
DoCmd.DoMenuIte m acFormBar, acEditMenu, acUndo, , acMenuVer70
End If

End If

Next ctl



When I move to another record this procedure runs, It's ok if I say No to the prompt, but when I say Yes, it gives me an error that says I cannot save the data.

Just for a test I place a Save button on the form. When I changed something on the record and clicked that Save button, it gives me an error.

What's wrong with my codes?
Sep 11 '06 #1
4 2199
PEB
1,418 Recognized Expert Top Contributor
Hi,

In Before Update event you don't need to save the record...

The form is automaticlly in process to do it if before update is run...

So to Cancel a Save you need to type

Cancel=true

and the changes are rejected...

So you don't need the longs

docmd.....

Have a nice day...
Sep 11 '06 #2
gazelle04
52 New Member
In the message prompt when I clicked "No" I already have that Cancel = True.

But when I clicked "Yes" that's where the error is. I included the DoCmd.Save method there because I needed to have something to prove that I already saved the record and If I didn't included the DoCmd.Save it will prompt me again if I move to another record.

I needed to show to the user the option to save or not whenever there are changes in the record.
Sep 11 '06 #3
PEB
1,418 Recognized Expert Top Contributor
About your code...

If multi controls are changed in your record, so this message will appear mult times...

It's better to use a variable like flag

Dim my_flag as boolean

my_flag=false

cycle controls for changes

If change of control
my_flag=true

end if

end cycle

if my_flag=true then
my_result= inputbox...
if my_result=false then cancel=true
end if

Try structure like this without any docmd...

And tell us what happens!

Have a nice day !

:)
Sep 11 '06 #4
gazelle04
52 New Member
The error number is 2115. It says that the BeforeUpdate or Validation rule prevents the database from saving the record. I'm not using any validation rules.

When I move to another record or if a form has lost its focus there should be a way to catch the record changes and there should be an option to cancel or save. So far I have catched the option to Cancel.
Sep 11 '06 #5

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

Similar topics

1
2868
by: Alex Wisnoski | last post by:
Access 97SR2-I am trying to create a Job Position data entry form based on a table. The form has 15 fields on it. I want to use a combo box to look in the table and see if the position number already exists. If the position exists, then pull up that record and display the information on the form. If the position doesn't exist, inform the user and ask if they want to add it. If they elect to add it, then have a new record to add it in...
1
2667
by: Alex.Wisnoski | last post by:
I have a data entry form with a combo box to look up an entrant's name. If the name is already in the table then it pulls up the record and that part of the form works fine. If the name isn't in the table then I want to be able to add it but this part is not working. I enter a name that is not in the table and press Enter. I step through the code and it appears to work until I get to "Exit Sub". At this point a warning message box...
2
2257
by: Deano | last post by:
In my app I have lots of forms with data presented in various ways using all kinds of controls. Is there a simple way of detecting if the user has changed any data? I would like to do this so I could set a boolean value to True and then I could use that to modify what is displayed on my reports. In my dim memory is there a dirty property for forms that would do this? Would that always work for every form? Most, if not all, of my...
4
5350
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. Currently everything is working. I can find the updated rows/columns by parsing the posted data collection against the DataGrid DataSource. However, when there is a large amount of DataGridItems (rows) the update processing can take a while. ...
1
1589
by: fred tate via .NET 247 | last post by:
I'm working on a project that will track a great deal of data forindividuals and will keep track of users for a very long time (5- 10) years. I'm looking for options as far as tracking anddisplaying changes to the data. Any suggestions for both the UIand the Data Storage aspects of tracking long term changes todata would be helpful. Fred Tate -------------------------------- From: fred tate ----------------------- Posted by a user...
6
2078
by: Frank Esser | last post by:
Hallo, I've got a project with about 10 pages. On each of them the user can do data changes (mostly datagrid interactions; the datagrids are bound to datasets). The user is able to jump to each page of my project without clicking on the "save" button and he can also close the browser without saving. My customer wants the user to be informed about loss of data. If any page is left without saving data changes then on the same page a...
7
1794
by: Mike McGavin | last post by:
Hi everyone. I'm searching for a quick and dirty way to have psql record the SQL statements that I enter, especially those related to the database structure. My main motivation is to help keep what will probably be a production server up-to-date with my development server. I've thought a little about replication, but the current options for that seem like overkill for the relatively small database that I have. I'm particularly
0
1297
by: Benzine | last post by:
I recently rolled out replication on our production server (MS SQL 2000 SP4) and every time a subscriber tries to sync the following always appears in the Merge Agent History: "Downloaded 100 data changes (0 inserts, 100 updates, 0 deletes, 0 conflicts)" Then at the very end of the "Action Messages" the following appears: "Merged 31489 data changes (453 inserts, 30893 updates, 143 deletes, 14
0
1051
by: Edwin Elston | last post by:
I'm new with Data Sources and am using VB.Net in VS2005, although I have VS2010 available if it matters. In previous code I just wrote queries using OleDbConnections and OleDbCommands but wanted to learn about using Data Sources. My requirements are pretty simple, the underlying data in the SQL database is modified from outside sources or triggers I wrote in the DB. For the purpose of this question, all I realy want to do is display in...
0
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8803
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8700
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7298
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.