473,503 Members | 1,676 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.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
Cancel = True
DoCmd.DoMenuItem 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 2186
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
2858
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...
1
2657
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...
2
2243
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...
4
5334
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. ...
1
1585
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...
6
2070
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...
7
1781
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...
0
1294
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...
0
1046
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...
0
7278
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
7328
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...
1
6988
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...
0
7456
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...
0
5578
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,...
0
4672
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...
0
3166
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...
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
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...

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.