Locking Fields

G

Guest

Hello,
I have a form that is set to not allow edits. There is an "edit" button, if
you will, that when clicked will set the form to allow edits. I have two
checkboxes on the form to set the record as "Active" or "In-Active".

What I would like to do is if the record is set to "In-Active" (In_Active =
True), I need ALL fields/controls on the form to be locked, with the
exception of the "Active" checkbox. The "Active" checkbox should remain
unlocked (Active.locked=False) so that if the recored need to be re-activated
users can click the "edit" button and select "Active" to unlock all the
fields/controls.

My question is, would I need to place each field/control in the "edit"
button code to state that when "edit" is clicked, if In_Active=True then
field.locked=true, or is there some kind of global command that could do this
for all fields/controls? I have quite a few fields/controls in the form!

I hope I explained this ok. If not, let me know of any questions you may
have. I thank you in advance for any assistance you may be able to provide.
 
P

Pieter Wijnen

I Really must get my website going <g>

Using the Tag Property & a TextBox (EditEnable)

Private Sub Form_Current()
Dim C As Access.Control
For Each C In Me.Controls
Select Case C.ControlType
Case acControlType.acListBox, acControlType.acComboBox,
acControlType.acTextBox, _
acControlType.acCheckBox, acControlType.acBoundObjectFrame, _
acControlType.acObjectFrame, acControlType.acOptionGroup, _
acControlType.acSubform, acControlType.acToggleButton
C.Locked = VBA.IIf(VBA.InStr(C.Tag, "ReadOnly") > 0, Not
Me.EditEnable.Value, C.Locked)
Case acControlType.acCommandButton
C.Enabled = VBA.IIf(VBA.InStr(C.Tag, "ReadOnly") > 0,
Me.EditEnable.Value, C.Enabled)
Case Else ' Don't bother
End Select
Next
End Sub

HTH

Pieter
 
P

Pieter Wijnen

Xerox Engineering , should be
Using the Tag Property & a CheckBox (EditEnable)

Pieter

"Pieter Wijnen"
I Really must get my website going <g>

Using the Tag Property & a TextBox (EditEnable)

Private Sub Form_Current()
Dim C As Access.Control
For Each C In Me.Controls
Select Case C.ControlType
Case acControlType.acListBox, acControlType.acComboBox,
acControlType.acTextBox, _
acControlType.acCheckBox, acControlType.acBoundObjectFrame, _
acControlType.acObjectFrame, acControlType.acOptionGroup, _
acControlType.acSubform, acControlType.acToggleButton
C.Locked = VBA.IIf(VBA.InStr(C.Tag, "ReadOnly") > 0, Not
Me.EditEnable.Value, C.Locked)
Case acControlType.acCommandButton
C.Enabled = VBA.IIf(VBA.InStr(C.Tag, "ReadOnly") > 0,
Me.EditEnable.Value, C.Enabled)
Case Else ' Don't bother
End Select
Next
End Sub

HTH

Pieter
 
G

Guest

Hi Pieter and thank you for your response. However, the code you provided is
a little beyond my knowledge. I see where you are going with this but am
unsure how to incorporate what I need into your code. Here is what I was
starting with which inspired me to submit my question. I guess I would need
to know hoe to incorporate my "Edit" button, which is actually just a label
(for appearance...i know but I like my program to look pretty too!). Anyway,
let me know if you could how I could incorporate what I have into what you
suggest. Here is what I started with...

Private Sub Edit_Label_Main_Click()

Me.AllowEdits = True
Me!DateModified = Now
If In_Active = True Then
Me!Active.Locked = False
Me!First_Name_A.Locked = True
Me!Last_Name_A.Locked = True
Else
Me!First_Name_A.Locked = False
Me!Last_Name_A.Locked = False
End If

End Sub

Thanks again Pieter for your assistance! I reeeeeeaaally appreciate it!


--
Randy Street
Rancho Cucamonga, CA


Pieter Wijnen said:
I Really must get my website going <g>

Using the Tag Property & a TextBox (EditEnable)

Private Sub Form_Current()
Dim C As Access.Control
For Each C In Me.Controls
Select Case C.ControlType
Case acControlType.acListBox, acControlType.acComboBox,
acControlType.acTextBox, _
acControlType.acCheckBox, acControlType.acBoundObjectFrame, _
acControlType.acObjectFrame, acControlType.acOptionGroup, _
acControlType.acSubform, acControlType.acToggleButton
C.Locked = VBA.IIf(VBA.InStr(C.Tag, "ReadOnly") > 0, Not
Me.EditEnable.Value, C.Locked)
Case acControlType.acCommandButton
C.Enabled = VBA.IIf(VBA.InStr(C.Tag, "ReadOnly") > 0,
Me.EditEnable.Value, C.Enabled)
Case Else ' Don't bother
End Select
Next
End Sub

HTH

Pieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top