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

How to change form to allow control of saving record changes?

167 100+
I have inherited an access database that has the forms designed so when a user makes a change in any column(text box), there is a bar on the left of the form and a pencil appears. If the user does not click on this pencil, the changes are not saved and there are no warning messages. We have found that lots of changes have been lost due to user's not clicking on the pencil. I have been asked to change the forms to put a 'Save record' button on the form. I also need to detect if they have made a change on the form and as soon as a change is made to set this new button to 'enabled'. They would like it to stay grayed out unless a change is made. If the user clicks on the 'x' button in the upper right corner to close the form or a existing button to take them back to the main menu, I want to check at the point if any data has been changed and display a message box prompting them if they want to save the changes.

I have done the following, changed the properties on the form for 'Record Selector' and 'Navigation Buttons' to 'No'.
I tried using the form event of 'Close' and put a test in for
Expand|Select|Wrap|Line Numbers
  1. If me.Dirty Then
  2.    intAnswer = MsgBox("The Asset info has been modified.  Do you want to save your changes?", vbYesNoCancel)
  3. End If
  4.  
When it hits this code, the "me.Dirty" is "false". I was expecting it to be "true" since I made a data change.

I may be going about this all the wrong way. The columns on my form are 'bound'. Any suggestions on the best way to handle this?

Thanks for any ideas!
Apr 18 '11 #1
10 2880
TheSmileyCoder
2,322 Expert Mod 2GB
Your approach seems sound enough. What other code is currently on the form? Especially look for the FORMs BeforeUpdate event, as well as the forms Dirty event.
Apr 18 '11 #2
ncsthbell
167 100+
Nothing is working correctly. I am not familiar with the form having a bar on the left side with a pencil showing up when a change it made. I need to figure out how this is done and how to get rid of it so I can control the save. I wonder if it is because the forms columns are 'bound'?
Apr 18 '11 #3
NeoPa
32,556 Expert Mod 16PB
It may be because they're unbound. So many newbies seem to want to handle data saving on forms without using the way Access provides (Bound forms etc). Maybe posting the form's module code would be helpful in this case. There may be some clues in there for us. Can you also include whether the form and the record controls are actually all bound.

PS. Using the CODE tags should be easier than typing in the tags. There is a hash (#) type button in the post window that will do it for you for any selected text.
Apr 18 '11 #4
ncsthbell
167 100+
All of the columns on the form are 'bound'. There is no code behind the form except for code that pertains to some combo boxes to handle 'not in list'. I want to detect when a data column value has been changed and capture the original value to store as history. I put code behind the 'before update' event of the data column and a 'stop' so I could look at the column value. The column value (txtDataCol1) contains the new value I just typed in. Since the columns are bound, does this mean it updates the table as soon as data is changed in a column? This seems like this should be an easy task, maybe I am over complicating it. Bottomline is all I want to to is detect when a column (bound) on the form has had a change made, and when it has, I want to write a history record to another table that contains the previous and the new column value.
Apr 19 '11 #5
NeoPa
32,556 Expert Mod 16PB
Please post the code rather than describing it.
Apr 19 '11 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Your post 5 description of your problem doesn't really match your post 1 description. So I am a bit unsure what you want.

If you need to access the old value of a textbox, you can use the
Expand|Select|Wrap|Line Numbers
  1. txtDataCol1.OldValue
to get to that value.

Personally for history purposes I use a second table with the same columns as the first table. Then in the forms before update event, if it is not a NewRecord, I run code to append the current record to the history table. Thus each time the forms before Update event fires, a copy of all the old values are appended to a seperate table.
Apr 26 '11 #7
ncsthbell
167 100+
This sounds like exactly what I need to do. I like the suggestion to store the record in a table and then append it to the history table. In the 'Forms before update' event code, how do I test to see if it is a new record or an update to the current record?
Apr 27 '11 #8
TheSmileyCoder
2,322 Expert Mod 2GB
For bound forms there is a simple, Me.NewRecord which will be true for records that have not yet been inserted into the table.

Something like this for table tbl_Test with primary KEY KEY_Test, in a form where the key field is bound to textbox tb_KEY
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel as Integer)
  2.   If not Me.NewRecord Then
  3.     Dim strSQL as string
  4.     strSQL="INSERT INTO histTbl_Test " & _
  5.            " SELECT * " & _
  6.            "FROM tbl_Test" & _
  7.            "WHERE tbl_Test.KEY_Test=" & Me.tb_KEY
  8.  
  9.     'Inline error handling
  10.     On Error Resume Next
  11.  
  12.     'Runquery
  13.     CurrentDB.Execute strSQL,dbfailonerror
  14.  
  15.     'Was query succesfull
  16.     If Err.nr<>0 then
  17.       'Update failed 
  18.       MsgBox "Could not save record"
  19.       Cancel=True
  20.       Exit Sub
  21.     End If
  22.  
  23.     'Resume Normal Error Handling
  24.     On Error goto 0
  25.     End If
  26. End Sub
Apr 27 '11 #9
ncsthbell
167 100+
Sorry, I apologize. I just re-read my post and I realize that I did kind of get off of the 1st post I made and made it a bit confusing. It all revolves around the same issue I was having, but should have been separate posts.
I am trying to figure out what the bar on the left of the form is that shows a 'pencil' once any data on the form has been changed. I don't want to display this bar with the pencil but instead put a button on the form for the user to select to 'save' the changes. Thus, was the reason I was trying to detect when a column was changed on the form. If they try to close the form after making a change, I wanted to detect it and prompt them to ask if they want to save the changes or cancel. However, I am confused about when the physical record is updated on the table since the columns are 'bound'. Is it updated when the data is entered in the column? Currently, the users click on the 'pencil' in the bar on the left to save the changes. I am not sure how to remove this bar and pencil.
Apr 28 '11 #10
TheSmileyCoder
2,322 Expert Mod 2GB
The bar on the left is the Record Selector. If you look at the forms properties you can set the "Record Selectors" property to False/No, to turn of the bar on the left. You confused me a bit because you made it sound like you were talking about a custom control in the database you inherited. In fact its standard built in Access.

The pencil is indicating that changes have been made to the record, but the record has not yet been saved. However, Access will always save your record when you: Move away from the form, browse to a new record, close the form, close the database. Exceptions to this could be if the record entered does not full-fill any validation rules or some required fields are not filed out. (Or if you press Esc, which triggers the undo action and discards the changes)

However, you can modify the save behavior by looking at the Forms Before_Update event.

Individual columns are not updated seperate from the "whole". A record consists of several fields (or columns) and are updated "together".
Apr 28 '11 #11

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

Similar topics

2
by: XxLicherxX | last post by:
Hi, Can someone tell me how I can open a form to a specific record from a button on another form. Here is what I want to have happen. I have one form called Computers and another form called...
13
by: Jim M | last post by:
I've been playing with Allen Browne's audit code and found it very useful. I need to track record insertions, deletions, and edits for several tables. I am planning to replace Access with Microsoft...
2
by: dbuchanan | last post by:
Hello, I want to open a child form based on the record selected in a dataGridView of the parent form. I want the child form to open with a populated child table based on the selected parent...
5
by: deekay | last post by:
I want to allow users to resize and reposition columns of a datasheet but for a prompt to be brought up and only the layout only to be saved if they select "save changes". This is the way it works...
1
by: Coll | last post by:
Hi - I'm trying to figure out how to append a record to a table and then open a form and display that record. My thought was to use the autonum primary key field (recordnum) and display the highest...
3
by: getro | last post by:
Hi Everyone, I need to open an Access 2003 form to a specific record from a custom Outlook 2003 Appointment form. The form has a command button that would pass a record id to access and open the...
2
by: angi35 | last post by:
I hope this is an easy question for someone out there. In Access 2000…I have a MainForm with a tab control (MAIN TABS) with 7 tabs. Within each tab is a SubForm. Within each SubForm is a tab...
3
by: Toireasa | last post by:
Hi all, In my form, where, each individual record is a Subject with various data attached, I've set up a combo box to select which record I want to look at. The macro doing this is a...
2
by: mileshenley | last post by:
Hey guys, im working on a project right now that has a form that needs to be filled out by applicants. Applicants also can go back later once the form has been submitted and edit the form if changes...
1
by: Duraivelan | last post by:
I am new to MS Access. I am using MS office XP. I want to get details from user in a form using unbound text boxes (with the same data type in the table fields), create a new record in the table and...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.