subform controls enable=false

J

JIM

Hi, here is code i'm using on the On Load event of my subform:

Private Sub Form_Load()
If CurrentProject.AllForms("frmClientBuildings").IsLoaded Or Parent.Name
= "frmWorkOrders" Then
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Static" Then ctl.Enabled = False
Next ctl
Else
If Parent.Name = "frmCustomer" Then 'allow edits if subform of
frmCustomers
Me.AllowEdits = True
Me.AllowAdditions = True
End If
End If
End Sub

If subform is loaded alone or is a subform of frmWorkOrders I don't want
user to have ability to edit certain fields. If subform is a subform of
frmCustomers then I want all fields enabled in order to edit. The problem
with this method is in form view all the controls that have Tag="Static" are
greyed out. I did a search on locked and other words but can't find another
word to use other than enabled. Is there another way to accomplish?
 
S

strive4peace

here is some code I modified from something AD Tejpal posted...

put this code in a general (standard) module

'~~~~~~~~~~~~~~~~~~~
Function GetSubFormParent(frm As Form) As string
' Returns True if frm is open as a subform
On Error Resume Next
if Not IsError(Len(frm.Parent.Name) > 0) then
GetSubFormParent = frm.Parent.Name
else
GetSubFormParent = ""
end if
End Function
'~~~~~~~~~~~~~~~~~~~

then, behind your form, try this:

'~~~~~~~~~~~~~~~~~~~
Dim ctl As Control
dim mBoo as boolean

mBoo = false

if GetSubFormParent(Me) = "frmCustomers" then
mBoo = true
end if

For Each ctl In Me.Controls
If ctl.Tag = "Static" Then ctl.Enabled = mBoo
Next ctl

Me.AllowEdits = mBoo
Me.AllowAdditions = mBoo

'~~~~~~~~~~~~~~~~~~~



Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
:) have an awesome day :)
*
 
J

JIM

I did try something similar to your reply but it didn't work for me and that
is why i'm setting each control enable=false separately. I need 2 controls,
command buttons, on form to be enabled. If I code Me.Allowedit and
Allowadditions = false -this disables all controls and I can't use my command
buttons. But I will try this tonight and let you know how it works. At any
rate I don't want the fields to grey-out even if fields are disabled.
Thanks so much for the input,
JIM
 
S

strive4peace

actually, there is NO need for changing AllowEdits if you are flipping
the enabled property of the controls

"I don't want the fields to grey-out even if fields are disabled."

then set the Locked property as well...

if enabled = false then Locked = true <smile>
so Locked is set opposite of Enabled

ctrl.Locked = NOT mboo


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
:) have an awesome day :)
*
 
J

JIM

Thanks Crystal, I used the locked = true instead for enabled = false and it
works perfect. Thanks for all your help.
JIM
He is my peace who has broken down every wall.
 

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