I've successfully created a button that locks/unlocks all the fields in a
form. In addition, it keeps all fields unlocked during initial record
creation, but requires the user to use the button whenever any fields in the
form are edited. This was accomplished by following the instructions and code
(see pasted at bottom of this post) at the following web address under
"Double-Action Command Button" posted on 3/28/08:
http://www.msaccesstips.com/labels/msaccess%20forms.shtml
This does almost exactly what I want, but I'd like to have one of the fields
on the form (a combo box field that looks up and returns a given record in
the rest of the form) not lock each time. That is, I'd like it to remain
unlocked and available for repeat use without having to click the lock/unlock
button each time. Is this possible?
Thanks
The code portion of the application is as follows:
Private Sub Form_Current()
If Me.NewRecord Then
With Me
.cmdEdit.Caption = "Edit"
.cmdEdit.ForeColor = 0
.cmdEdit.FontBold = False
.AllowEdits = True
.cmdEdit.Enabled = False
End With
Else
With Me
.AllowEdits = False
.cmdEdit.Caption = "Edit"
.cmdEdit.ForeColor = 0
.cmdEdit.FontBold = False
.cmdEdit.Enabled = True
End With
End If
End Sub
AND
Private Sub cmdEdit_Click()
Dim cap As String
cap = Me.cmdEdit.Caption
Select Case cap
Case "Edit"
With Me
.AllowEdits = True
.cmdEdit.Caption = "Lock"
.cmdEdit.ForeColor = 128
.cmdEdit.FontBold = True
.Refresh
End With
Case "Lock"
With Me
.AllowEdits = False
.cmdEdit.Caption = "Edit"
.cmdEdit.ForeColor = 0
.cmdEdit.FontBold = False
.Refresh
End With
End Select
End Sub
|
|
0
|
|
|
|
Reply
|
Rlong
|
2/11/2010 5:37:21 AM |
|
Take a look at this article:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html
You copy the code from the webpage into a standard module, and set your
form's On Load property to:
=LockBoundControls([Form],True)
You can optionally add the name of any controls that should not be locked
inside the brackets as well, in quotes and separated by commas. So, if you
want Combo1 to remain unlocked at all times, use:
=LockBoundControls([Form],True, "Combo1")
The code automatically locks any subforms you have on your form (nested to
any depth.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Rlong" <u58125@uwe> wrote in message news:a372eecf4d5db@uwe...
> I've successfully created a button that locks/unlocks all the fields in a
> form. In addition, it keeps all fields unlocked during initial record
> creation, but requires the user to use the button whenever any fields in
> the
> form are edited. This was accomplished by following the instructions and
> code
> (see pasted at bottom of this post) at the following web address under
> "Double-Action Command Button" posted on 3/28/08:
>
> http://www.msaccesstips.com/labels/msaccess%20forms.shtml
>
> This does almost exactly what I want, but I'd like to have one of the
> fields
> on the form (a combo box field that looks up and returns a given record in
> the rest of the form) not lock each time. That is, I'd like it to remain
> unlocked and available for repeat use without having to click the
> lock/unlock
> button each time. Is this possible?
>
> Thanks
>
>
> The code portion of the application is as follows:
>
> Private Sub Form_Current()
> If Me.NewRecord Then
> With Me
> .cmdEdit.Caption = "Edit"
> .cmdEdit.ForeColor = 0
> .cmdEdit.FontBold = False
> .AllowEdits = True
> .cmdEdit.Enabled = False
> End With
> Else
> With Me
> .AllowEdits = False
> .cmdEdit.Caption = "Edit"
> .cmdEdit.ForeColor = 0
> .cmdEdit.FontBold = False
> .cmdEdit.Enabled = True
> End With
> End If
>
> End Sub
>
>
> AND
>
>
> Private Sub cmdEdit_Click()
> Dim cap As String
> cap = Me.cmdEdit.Caption
> Select Case cap
> Case "Edit"
> With Me
> .AllowEdits = True
> .cmdEdit.Caption = "Lock"
> .cmdEdit.ForeColor = 128
> .cmdEdit.FontBold = True
> .Refresh
> End With
> Case "Lock"
> With Me
> .AllowEdits = False
> .cmdEdit.Caption = "Edit"
> .cmdEdit.ForeColor = 0
> .cmdEdit.FontBold = False
> .Refresh
> End With
> End Select
> End Sub
>
|
|
0
|
|
|
|
Reply
|
Allen
|
2/11/2010 8:47:18 AM
|
|
Thanks, Allen! This code works as well, and it's helpful to be able to unlock
individual controls. I do, however, like the way the other code "relocks" the
form after editing any single field, so you don't accidently leave the form
unlocked. I'm wondering if there's a way, using the original code that I
posted, to include a line or two that would leave individual controls
unlocked? Any ideas? I'm a fairly low-level code writer, so I'll need to rely
on others for this one.
Thanks again.
Allen Browne wrote:
>Take a look at this article:
> Locking bound controls on a form and subforms
>at:
> http://allenbrowne.com/ser-56.html
>
>You copy the code from the webpage into a standard module, and set your
>form's On Load property to:
> =LockBoundControls([Form],True)
>You can optionally add the name of any controls that should not be locked
>inside the brackets as well, in quotes and separated by commas. So, if you
>want Combo1 to remain unlocked at all times, use:
> =LockBoundControls([Form],True, "Combo1")
>
>The code automatically locks any subforms you have on your form (nested to
>any depth.)
>
>> I've successfully created a button that locks/unlocks all the fields in a
>> form. In addition, it keeps all fields unlocked during initial record
>[quoted text clipped - 64 lines]
>> End Select
>> End Sub
--
Message posted via http://www.accessmonster.com
|
|
0
|
|
|
|
Reply
|
Rlong
|
2/11/2010 9:56:20 PM
|
|
There are multiple problems with the original code's working/reliability, so
I'm not sure I can sort it out for you.
Examples:
- You have to hard-code the names of the controls in the code.
- Setting AllowEdits has other side effects (e.g. entire form disappears if
there are no records, and its effect on subforms.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Rlong via AccessMonster.com" <u58125@uwe> wrote in message
news:a37df3fe5f872@uwe...
> Thanks, Allen! This code works as well, and it's helpful to be able to
> unlock
> individual controls. I do, however, like the way the other code "relocks"
> the
> form after editing any single field, so you don't accidently leave the
> form
> unlocked. I'm wondering if there's a way, using the original code that I
> posted, to include a line or two that would leave individual controls
> unlocked? Any ideas? I'm a fairly low-level code writer, so I'll need to
> rely
> on others for this one.
>
> Thanks again.
>
>
>
> Allen Browne wrote:
>>Take a look at this article:
>> Locking bound controls on a form and subforms
>>at:
>> http://allenbrowne.com/ser-56.html
>>
>>You copy the code from the webpage into a standard module, and set your
>>form's On Load property to:
>> =LockBoundControls([Form],True)
>>You can optionally add the name of any controls that should not be locked
>>inside the brackets as well, in quotes and separated by commas. So, if you
>>want Combo1 to remain unlocked at all times, use:
>> =LockBoundControls([Form],True, "Combo1")
>>
>>The code automatically locks any subforms you have on your form (nested to
>>any depth.)
>>
>>> I've successfully created a button that locks/unlocks all the fields in
>>> a
>>> form. In addition, it keeps all fields unlocked during initial record
>>[quoted text clipped - 64 lines]
>>> End Select
>>> End Sub
>
> --
> Message posted via http://www.accessmonster.com
>
|
|
0
|
|
|
|
Reply
|
Allen
|
2/12/2010 12:54:07 AM
|
|
Thanks for thinking about it. Even with my limited coding experience I
thought that this code looked a little simplistic and un-elegant. Maybe I'll
work with the other set of code instead and try to build in some of the
safeguards I'm looking for.
Allen Browne wrote:
>There are multiple problems with the original code's working/reliability, so
>I'm not sure I can sort it out for you.
>
>Examples:
>- You have to hard-code the names of the controls in the code.
>
>- Setting AllowEdits has other side effects (e.g. entire form disappears if
>there are no records, and its effect on subforms.)
>
>> Thanks, Allen! This code works as well, and it's helpful to be able to
>> unlock
>[quoted text clipped - 32 lines]
>>>> End Select
>>>> End Sub
--
Message posted via http://www.accessmonster.com
|
|
0
|
|
|
|
Reply
|
Rlong
|
2/12/2010 1:08:24 AM
|
|
|
4 Replies
2691 Views
(page loaded in 2.11 seconds)
Similiar Articles: Lock/unlock form button - microsoft.public.access.forms ...I've successfully created a button that locks/unlocks all the fields in a form. In addition, it keeps all fields unlocked during initial record crea... locking and unlocking a textbox using command buttons - microsoft ...I have a userform with a textbox (TextBox1) on it linked to a cell in the spreadsheet. I have two command buttons on the form : cmdLock and cmdUn... Lock and unlock records - microsoft.public.access.forms ...Lock/unlock form button - microsoft.public.access.forms ... I've successfully created a button that locks/unlocks all the fields in a form. In addition, it keeps all ... Lock a form - microsoft.public.access.formsLock/unlock form button - microsoft.public.access.forms ... I've successfully created a button that locks/unlocks all the fields in a form. In addition, it keeps all ... How to unlock fields on form to add - microsoft.public.access ...How to unlock fields on form to add - microsoft.public.access ... Lock/unlock form button - microsoft.public.access.forms ... How to unlock fields on form to add ... all fields in editable subform behave as locked even though they a ...Lock/unlock form button - microsoft.public.access.forms ... all fields in editable subform behave as locked even though they a ... Lock/unlock form button - microsoft ... New page - Locking fields on a form in Microsoft Access ...I have some unbound sub-forms allowing entry of data ... When I went to add the new field to my form in Access ... Lock/unlock form button - microsoft.public.access.forms ... Lock Combo Box - microsoft.public.accessLock/unlock form button - microsoft.public.access.forms ... Combo box locked unless unlock button selected - microsoft.public ... I have a form that locks the records when ... locked table error - microsoft.public.access.formsI am trying to open a report via a control button on a form. The form is based off of ... Procedure Table Locking problem Bracketing a call to an sproc with LOCK/UNLOCK ... Unlock [all]? or unlock [associated] - microsoft.public.onenote ...I have two command buttons on the form : cmdLock and cmdUnlock What I am looking for is for code for the cmd buttons which will lock and unlock the textbox for ... Lock/unlock form button - microsoft.public.access.forms ...I've successfully created a button that locks/unlocks all the fields in a form. In addition, it keeps all fields unlocked during initial record crea... Lock/unlock form button DataBase - DataBase Discussion List ...I have successfully created a button that locks/unlocks all the fields in a form. In addition, it keeps all fields unlocked during initial record creation lock unlock fields form from ribbon buttonI'm trying to make a button of the Ribbon can lock / unlock the form fields for editing. I need help on how to do , so far the code I use is not working ... Microsoft Access: Lock/unlock button on form - database.itags.orgdatabase.itags.org: Microsoft Access question: Lock/unlock button on form, created at:Fri, 06 Jun 2008 13:15:00 GMT with 919 bytes, last updated: Saturday, July 14 ... Unlocking (and Locking) Forms in Word 2007 | the MOST - McCombs BlogsThere is an additional way to show the Lock tool. Use this method if you need to unlock the form and be able to insert or edit form fields: 1. Click the Office Button. 7/22/2012 11:26:16 AM
|