Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 16th, 2007, 12:52 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Prevent accidental update from a form

I would like to restrict changes to the displayed data in a form from updating the underlying record unless a control is clicked. This would protect against unintended changes to the table.

I don't know how to do this.

Reply With Quote
  #2 (permalink)  
Old January 16th, 2007, 12:56 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

The easiest way that I have found of doing this is to set the Locked property of each control to True. Then if you have an Edit button or something, on the Click event for that button unlock each control.

txtTextBox.Locked = False

The other way is to do this is to make the enabled property false, and make it true when the edit button is clicked.

The difference is that when a control is disabled, it will be grayed out, whereas when it is locked the only this different is that you can't change the data.

Hope that helps,

Mike

Mike
EchoVue.com
Reply With Quote
  #3 (permalink)  
Old January 16th, 2007, 01:23 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply, Mike.
I moving from being a casual Access user to having responsibility for creating an application from scratch. I am very experienced in system design and databases, but new to VBA and the technical aspects of Access.

The form is a personnel update. It contains several combo boxes to select, for example, the person's manager. I would like it to work like Quicken, where you can change a record, but must click a control to perform the update. If I understand your notes, it would work differently.

 I could have all the controls and text boxes locked, and use a control click to unlock them. Then, any changes would update the record. I would lock the controls again when the user moves to a different record. Also, all would be unlocked when adding a new record.

I have a problem interpreting the events, and selecting the right one for the action

Reply With Quote
  #4 (permalink)  
Old January 16th, 2007, 03:54 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

To do all of them at once instead of one field at a time, you can set the AllowEdits, AllowAdditions, and AllowDeletions properties of the form to False. Then you can have a button that toggles them from True to False and back. A label then could be changed to let the user know if, say, you're in "EDIT" or "VIEW" mode.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #5 (permalink)  
Old January 16th, 2007, 04:12 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great:D
They click the control, I change AllowEdits to True, and display a label that tells them they are in edit mode. When they move to another record, I want to change AllowEdits back to false. What is the appropriate form event?

Reply With Quote
  #6 (permalink)  
Old January 16th, 2007, 04:13 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

And there you have a better answer!!

Thanks Greg - Why didn't I ask this question 6 months ago?

Mike
EchoVue.com
Reply With Quote
  #7 (permalink)  
Old January 16th, 2007, 04:16 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Change the three properties to False on the form's ON CURRENT event.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #8 (permalink)  
Old January 16th, 2007, 04:20 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is a very easy way for me to get smarter.

I hope that in time, I will know enough to contribute!

Reply With Quote
  #9 (permalink)  
Old January 18th, 2007, 10:51 AM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I implemented your solution, but created a problem. I use a combo box to select the person's record, and allowedits = false prevents the combo box from working. I added a control cmdFindName to set allowedits to true. This works, but seems awkward. Here's my code. Better suggestions?


Private Sub cmdFindName_Click()
' enable cboFindName
On Error GoTo Err_cmdFindName_Click
    Me.AllowEdits = True
    lblFindName.Visible = True
Exit_cmdFindName_Click:
    Exit Sub

Err_cmdFindName_Click:
    MsgBox (Err.Number & " " & Err.Description)
    Resume Exit_cmdFindName_Click

End Sub
Private Sub cboFindName_AfterUpdate()
    ' Find the record that matches the control.
    On Error GoTo Err_cboFindName_After
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[Email] = '" & Me![cboFindName] & "'"
    Me.Bookmark = rs.Bookmark
    Me.AllowEdits = False
Exit_cboFindName_After
    Exit Sub

Err_cboFindName_After:

    Resume Exit_cboFindName_After
End Sub



Reply With Quote
  #10 (permalink)  
Old January 18th, 2007, 10:55 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Is your combo-box bound to the email field? I think if you remove the bound control from this control, but keep the datasource, you should be able to use it even when Editing is turned off.

Of course I could be way out in left field too.

Mike

Mike
EchoVue.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate running total on form and prevent text Hughesie78 ASP.NET 2.0 Basics 0 November 27th, 2007 10:35 AM
UpDate Records on a Form ManFriday Access 2 September 8th, 2007 04:21 AM
Update Table From Form ksbrain Access 2 January 9th, 2007 01:49 PM
How to Update a Listbox on Different Form boxwalah C# 2 February 24th, 2006 12:22 PM
Locking down my Form to prevent close or break donaldjlynch Access VBA 1 July 27th, 2003 09:37 PM



All times are GMT -4. The time now is 09:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.