Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lock all records in subform

Status
Not open for further replies.

mrbboy

Technical User
Feb 28, 2007
136
US
My subform contains several combo boxes and text boxes. Users will enter data into all these fields. I want to place a command button on the subform so that when it's clicked, all the fields on the subform are locked. Can this be done?
 
Yes. You can loop thru all controls and set their LOCKED property to TRUE.
Code:
    Dim ctrl As Control
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Then ctrl.Locked = True
    Next ctrl




Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
GingerR,

I was reading your response to mrbboy today that wants to place a command button on the subform so that when it's clicked, all the fields on the subform are locked.

You replied Yes, you can loop thru all controls and set their LOCKED property to TRUE.. I have a similar need, but what I also need is a command button when clicked un-locks the combo boxes and text boxes so information can be edited. Then re-lock the combo boxes and text boxes when I’m finished.

Can this be done?

[pc]

 
How are ya mrbboy & MikeFL . . .

Be aware . . . although setting the [blue]Locked[/blue] property of controls prevents editing/deleting data of said controls, it [blue]doesn't prevent deletion of the currently selected record![/blue]

You may want to give a little more thought here [surprise] . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Also, it doesn't lock them forever. Next time you open the form, they'll be unlocked. You'd then want to put code in your Form's OnOpen event that maybe opens the form where ALLOW EDITS = False or locks certain controls. Depends on what you are looking for. The only time any of my customers has requested this is to protect themselves from themselves: they don't want to make a mistake. And like Aceman says, they can still get into the data if they really want to. "Locking" is just an illusion. If I want to "keep people out" then I have a secure server that doesn't allow them in; Or only allow users in to look but not touch. A variety of solutions depending on what you are really looking for.

By the way, MikeFL...just set the LOCKED property in the code above to FALSE :)

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top