473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
Nov 12 '05 #1
4 2304
No, it is not enough.
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:eL*************@tk2msftngp13.phx.gbl...
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" <sa******@REMOVETHIShotmail.com> wrote in message
news:0v******************@wagner.videotron.net...
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


Nov 12 '05 #2
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" <sa******@REMOVETHIShotmail.com> wrote in message
news:mS******************@wagner.videotron.net...
No, it is not enough.
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:eL*************@tk2msftngp13.phx.gbl...
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" <sa******@REMOVETHIShotmail.com> wrote in message
news:0v******************@wagner.videotron.net...
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



Nov 12 '05 #3
rkc

"Saintor" <sa******@REMOVETHIShotmail.com> wrote in message
news:0v******************@wagner.videotron.net...
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.


Nov 12 '05 #4
> 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.
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a...
3
by: A Clark | last post by:
I have a subform that displays a datasheet. There are a couple of different queries that can be displayed in the datasheet. The queries are available in a combo box on the main form. The problem...
15
by: Susan Bricker | last post by:
Greetings. I have a Mainform with a subform. The Mainform has single record format and subform has continuous form format. When the Mainform opens, I force allowadditions and allowedits to FALSE...
6
by: GaryDave | last post by:
My school registration database has not been quite right after a recent compact and repair (done while I was away). Though most of the many forms and subforms are working normally, one form in...
4
by: vidiot | last post by:
I am trying to create a subform that will display images related to the parent form. The subform is a continuous form as there will be several images that relate to the parent form. I checked...
2
by: ncsthbell | last post by:
I have a form with a subform and I am trying to change the size of a column on the subform. I am following the instructions in the access help 'Change the layout of a subform in Datasheet view" to...
8
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Form is: Forms!FormName..RowSource = "TableOrQueryName"
4
by: MPat | last post by:
Hi!! I've been trying to figure this out.. I have a form with a subform and I need to display 2 different things in this subform, that's why I came with the idea of changing the Link Child Field...
7
AccessIdiot
by: AccessIdiot | last post by:
This is driving me nuts. I have an unbound textbox (txt_SumSize) in my subform that holds the total of a field (Debitage_Size_Quantity)seen in datasheet view (control source =Sum(). I have an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.