View Full Version : AllowEdit


Angello Pimental
05-22-2001, 09:33 AM
I have a form on which I have a command button that toggles between locking/unlocking a record for editing. Using the code:

Private Sub Command61_Click()
If Command61.Caption = "UNLOCK RECORDS" Then
Me.AllowEdits = True
Command61.Caption = "LOCK RECORDS"
Me.Refresh
Else
Me.AllowEdits = False
Command61.Caption = "UNLOCK RECORDS"
Me.Refresh
End If
End Sub

Question: The command button locks/unlocks every text box, and combobox. But how can I make it only lock/unlock specific text boxes/comboboxes?

Any help would be great.

Thnx

charityg
05-22-2001, 10:15 AM
I dug this post up. I think it's what you need. Finally a reason to use the tag property!
There's another way that doesn't rely on common field names. Use the "Tag" property to give a common group name to all of the fields that you want to enable/disable. In this example, they are tagged "Test_Quest". Then use some code like this:
Dim frmMyForm As Form
Dim ctlMyCtls As Control
Set frmMyForm = Forms!fMyWonderfulForm

'additional code here

' To turn on the whole group:
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "Test_Quest" Then
ctlMyCtls.Visible = True
ctlMyCtls.Enabled = True
End If
Next ctlMyCtls
' do whatever else
Set frmMyForm = Nothing

Angello Pimental
05-22-2001, 12:11 PM
Thanks Charity for the reply and advice...
I will give it a try.
Do you know if the AllowEdits function just works for an entire form, or can you get it to work for individual text boxes and combo boxes?

Thnx again,

Cheers

charityg
05-22-2001, 12:44 PM
AllowEdits is a form property. To block changes to individual form controls, you need to set the control's locked property to either true or false.