Locking a form (?)

  • Thread starter Thread starter Andreea Rotaru
  • Start date Start date
A

Andreea Rotaru

I have a table that contains extremely important information, which is
RARELY updated. I have created a form to access this information, but
any change I make in the table using the form will be saved
automatically. The problem is that I don't want this data to be
changed by mistake. Is it any way to temporarily lock the content of
the form/table? Or ANY other solution, to prevent unwanted changes is
welcome (I would prefer though not to take the writing privileges from
users). Thanks in advance!

Andreea
 
I would add a routine in the BeforeUpdate event that looks to see if the
record has been changed. If it has, I would pop up a warning asking the
user to verify the changes. If they client cancel, then the changes should
not be saved.

I have seen details on how to do this in this message group (or the
formscoding) recently so you might be able to do a search for it if you need
more details.

You could even ask the user to verify that they would like to save the
changes by having a box pop up and require the user to type a word (such as
"YES") to confirm.

HTH

Rick



I have a table that contains extremely important information, which is
RARELY updated. I have created a form to access this information, but
any change I make in the table using the form will be saved
automatically. The problem is that I don't want this data to be
changed by mistake. Is it any way to temporarily lock the content of
the form/table? Or ANY other solution, to prevent unwanted changes is
welcome (I would prefer though not to take the writing privileges from
users). Thanks in advance!

Andreea
 
To cancel changes if the user cancels, just add two lines to the
BeforeUpdate even proc.:
Me.Undo
Me.Undo

Ragnar
 
That sound great but I have never used this feature (I have been
working only for short time with Access, and so far I didn't do
anything too complicated). I tried to do what you have suggested in a
macro, but there is no "undo" command, and I have never used Visual
Basic. I looked in archives but most people give only part of their
code, so that is not very useful either. Is it anywhere online a
website where I can get more info about this. I would really
appreciate any help!

Thank you a lot!
Andreea
 
Hello Andrea,

You should be able to find all the info you need in the Access' buil-in
help, but there is also lots of info on the Web.
Below is some sample code from a Web site called The Access Web,
http://www.mvps.org/access/ to do just this.
To create the BeforeUpdate sub you open the form in design mode, display the
Properties pane (There is a button on the toolbar).
Then scroll down in the window untill you see the property Before Update.
Then click in the right hand end of the empty box next to Before Update and
select [Event Procedure]. Then click on the little button to the rigth of
the box and the Visual Basic editor window opens with the first and the last
line of the sub already entered.
Then you select all but the first and thelast line of the code below, hit
the save button, and you are all set.

BTW, Visual Basic is easy to learn and well wort the effort. Macros should
be avoided if at all possible, Macros can do most of the basic operations
you can do with code but they are confusing and can not be debugged easily.
In VB you can step through your code line by line and see excatly what
happens, you can look at the values of all the variables.

Ragnar
----------------------------------------------------------------------------
--------------

(Q) How can I control when a record is saved in a form?

(A) Use the form's BeforeUpdate event to run code each time Access tries
to save a record. This way, if the user doesn't want to save a record,
you can issue an Undo command instead of saving the record.

Note: This will generate a Message Box asking for confirmation each time a
changed record is saved. I leave it on whoever is going to follow this
method to determine how to refine this per user preference. (Hint: Try a
Checkbox.)

'****************** Code Start ******************Private Sub
Form_BeforeUpdate(Cancel As Integer)Dim strMsg As String strMsg = "Data
has changed." strMsg = strMsg & "@Do you wish to save the changes?"
strMsg = strMsg & "@Click Yes to Save or No to Discard changes." If
MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then 'do
nothing Else DoCmd.RunCommand acCmdUndo 'For Access
95, use DoMenuItem instead 'DoCmd.DoMenuItem acFormBar, acEditMenu,
acUndo, , acMenuVer70 End IfEnd Sub'****************** Code End
******************
 
Back
Top