What should I change in this code to use with a subform


S

Saintor

The following function works when used directly from a form. It locks
controls depending on a value stored in the tag property. Called from a
button on a subform, it does not work [UpdFormPropsLock(me.name, 3, true,
0)]. TIA.


Public Function UpdFormPropsLock(sForm As String, sLockLevel As Integer,
bSign As Boolean, Optional iJump As Integer) As Boolean
Dim sM1 As String

On Error Resume Next

If CurrentUserInGroup("Quality 1") = False And CurrentUserInGroup("Quality
2") = False And CurrentUserInGroup("Admins") = False Then
sM1 = "You have not the authorization to perform this operation."
If sLang = "F" Then sM1 = DLookup("CtlValue_FR", "tblLang",
"FormName='00056'")
MsgBox sM1, vbExclamation
Exit Function
End If


Dim doc As Document
Dim frm As Form
Dim ctl As Control
Dim Prop As Property
Dim sA As String
Set frm = Forms(sForm)

For Each ctl In frm.Controls

For Each Prop In ctl.Properties
Select Case ctl.ControlType
Case acCheckBox, acOptionGroup, acTextBox, acComboBox, acListBox
If Prop.Name = "Tag" Then
If IsNull(Prop.Value) = True Or Prop.Value = "" Then
GoTo goto_next

ElseIf Prop.Value > 0 And Prop.Value <= CStr(sLockLevel) Then
ctl.Locked = True

ElseIf Prop.Value > CStr(sLockLevel) And Prop.Value <= "9" Then
ctl.Locked = False
End If
End If

Case acCommandButton
If Prop.Name = "Tag" Then
If Prop.Value > "0" And Prop.Value <= CStr(sLockLevel) Then
If bSign = True Then frm!LockLevel.SetFocus
ctl.Enabled = False
ElseIf Prop.Value > CStr(sLockLevel) And Prop.Value < "9" Then
If bSign = True Then frm!LockLevel.SetFocus
ctl.Enabled = True
End If
End If

Case acSubform
If Prop.Name = "Tag" Then
If Prop.Value <= CStr(sLockLevel) Then
ctl.Enabled = False
ElseIf Prop.Value > CStr(sLockLevel) Then
ctl.Enabled = True
End If
End If

End Select
goto_next:
Next Prop
Next ctl

frm!LockLevel = sLockLevel
frm.Refresh
UpdFormPropsLock = True

Set Prop = Nothing
Set ctl = Nothing
Set frm = Nothing
Set doc = Nothing

End Function
 
Ad

Advertisements

S

Saintor

No, it is not enough.


Wayne Morgan said:
In the call, try changing Me.Name to Me.Parent.Name in order to send the name of the main
form.

--
Wayne Morgan
Microsoft Access MVP


Saintor said:
The following function works when used directly from a form. It locks
controls depending on a value stored in the tag property. Called from a
button on a subform, it does not work [UpdFormPropsLock(me.name, 3, true,
0)]. TIA.


Public Function UpdFormPropsLock(sForm As String, sLockLevel As Integer,
bSign As Boolean, Optional iJump As Integer) As Boolean
Dim sM1 As String

On Error Resume Next

If CurrentUserInGroup("Quality 1") = False And CurrentUserInGroup("Quality
2") = False And CurrentUserInGroup("Admins") = False Then
sM1 = "You have not the authorization to perform this operation."
If sLang = "F" Then sM1 = DLookup("CtlValue_FR", "tblLang",
"FormName='00056'")
MsgBox sM1, vbExclamation
Exit Function
End If


Dim doc As Document
Dim frm As Form
Dim ctl As Control
Dim Prop As Property
Dim sA As String
Set frm = Forms(sForm)

For Each ctl In frm.Controls

For Each Prop In ctl.Properties
Select Case ctl.ControlType
Case acCheckBox, acOptionGroup, acTextBox, acComboBox, acListBox
If Prop.Name = "Tag" Then
If IsNull(Prop.Value) = True Or Prop.Value = "" Then
GoTo goto_next

ElseIf Prop.Value > 0 And Prop.Value <= CStr(sLockLevel) Then
ctl.Locked = True

ElseIf Prop.Value > CStr(sLockLevel) And Prop.Value <= "9" Then
ctl.Locked = False
End If
End If

Case acCommandButton
If Prop.Name = "Tag" Then
If Prop.Value > "0" And Prop.Value <= CStr(sLockLevel) Then
If bSign = True Then frm!LockLevel.SetFocus
ctl.Enabled = False
ElseIf Prop.Value > CStr(sLockLevel) And Prop.Value < "9" Then
If bSign = True Then frm!LockLevel.SetFocus
ctl.Enabled = True
End If
End If

Case acSubform
If Prop.Name = "Tag" Then
If Prop.Value <= CStr(sLockLevel) Then
ctl.Enabled = False
ElseIf Prop.Value > CStr(sLockLevel) Then
ctl.Enabled = True
End If
End If

End Select
goto_next:
Next Prop
Next ctl

frm!LockLevel = sLockLevel
frm.Refresh
UpdFormPropsLock = True

Set Prop = Nothing
Set ctl = Nothing
Set frm = Nothing
Set doc = Nothing

End Function
 
W

Wayne Morgan

Ok, I took it that you were wanting to continue to lock the controls on the main form, but
place the button on the subform. Are you actually wanting to lock the controls on the
subform? You didn't specify WHAT doesn't work and WHAT you want it to actually do.

--
Wayne Morgan
Microsoft Access MVP


Saintor said:
No, it is not enough.


Wayne Morgan said:
In the call, try changing Me.Name to Me.Parent.Name in order to send the name of the main
form.

--
Wayne Morgan
Microsoft Access MVP


Saintor said:
The following function works when used directly from a form. It locks
controls depending on a value stored in the tag property. Called from a
button on a subform, it does not work [UpdFormPropsLock(me.name, 3, true,
0)]. TIA.


Public Function UpdFormPropsLock(sForm As String, sLockLevel As Integer,
bSign As Boolean, Optional iJump As Integer) As Boolean
Dim sM1 As String

On Error Resume Next

If CurrentUserInGroup("Quality 1") = False And CurrentUserInGroup("Quality
2") = False And CurrentUserInGroup("Admins") = False Then
sM1 = "You have not the authorization to perform this operation."
If sLang = "F" Then sM1 = DLookup("CtlValue_FR", "tblLang",
"FormName='00056'")
MsgBox sM1, vbExclamation
Exit Function
End If


Dim doc As Document
Dim frm As Form
Dim ctl As Control
Dim Prop As Property
Dim sA As String
Set frm = Forms(sForm)

For Each ctl In frm.Controls

For Each Prop In ctl.Properties
Select Case ctl.ControlType
Case acCheckBox, acOptionGroup, acTextBox, acComboBox, acListBox
If Prop.Name = "Tag" Then
If IsNull(Prop.Value) = True Or Prop.Value = "" Then
GoTo goto_next

ElseIf Prop.Value > 0 And Prop.Value <= CStr(sLockLevel) Then
ctl.Locked = True

ElseIf Prop.Value > CStr(sLockLevel) And Prop.Value <= "9" Then
ctl.Locked = False
End If
End If

Case acCommandButton
If Prop.Name = "Tag" Then
If Prop.Value > "0" And Prop.Value <= CStr(sLockLevel) Then
If bSign = True Then frm!LockLevel.SetFocus
ctl.Enabled = False
ElseIf Prop.Value > CStr(sLockLevel) And Prop.Value < "9" Then
If bSign = True Then frm!LockLevel.SetFocus
ctl.Enabled = True
End If
End If

Case acSubform
If Prop.Name = "Tag" Then
If Prop.Value <= CStr(sLockLevel) Then
ctl.Enabled = False
ElseIf Prop.Value > CStr(sLockLevel) Then
ctl.Enabled = True
End If
End If

End Select
goto_next:
Next Prop
Next ctl

frm!LockLevel = sLockLevel
frm.Refresh
UpdFormPropsLock = True

Set Prop = Nothing
Set ctl = Nothing
Set frm = Nothing
Set doc = Nothing

End Function
 
R

rkc

Saintor said:
The following function works when used directly from a form. It locks
controls depending on a value stored in the tag property. Called from a
button on a subform, it does not work [UpdFormPropsLock(me.name, 3, true,
0)]. TIA.


Public Function UpdFormPropsLock(sForm As String, sLockLevel As Integer,
bSign As Boolean, Optional iJump As Integer) As Boolean
Dim doc As Document
Dim frm As Form
Dim ctl As Control
Dim Prop As Property
Dim sA As String
Set frm = Forms(sForm)

It's not clear whether you want the function to operate on the controls on
the
subform or the controls on the parent form. Either way, I would change the
declaration

UpdFormPropsLock(sForm As String, to
UpdFormPropsLock(frmForm as Access.Form,

and then pass either Me or Me.Parent instead of trying to set the from
using the form's name and the Forms collection.
 
Ad

Advertisements

S

Saintor

Either way, I would change the
declaration

UpdFormPropsLock(sForm As String, to
UpdFormPropsLock(frmForm as Access.Form,

and then pass either Me or Me.Parent instead of trying to set the from
using the form's name and the Forms collection.

This alone made the difference and solved my problem. Thanks to all.
 

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