Problem locking bound controls

J

jtb3

Good morning, Reading this discussion group's threads made me aware of Allen
Browne's very informative website. I have tried to implement his program for
locking bound controls on a test form and subform
(http://allenbrowne.com/ser-56.html). I have created a tblTest with a PK
composed of an AutoNumber and a TestID; there is also a field [Vendor] in the
table. I then created a table for the subform with a FK = TestID (linked to
PK Master/Child and whose "Visible" attribute = False) and a field for
[Group]. All of these fields are formatted as text with the exception of the
AutoNumber field. The mainform, formTest, contains a bound text box [TestID],
a bound combo box [Vendor], and a command button 'Lock/Unlock'. I then
inserted a TabCtrl on the form to add the subform. Mr Browne's program works
well to this point. As soon as I add a subform (with a bound text box
[TestID] and a bound combo box [Group]) the program gives the error 2465 -
Application-defined or Object-defined error and the command button does not
change but remains fixed in the 'Lock' mode with the red rectangle
(indicating a locked record) visible. Originally if the red rectangle was
visible, the command button showed "Unlock" which allowed access for
edits/data entry. The line of code that gives the error is in this Function
(abbreviated to save space):

Public Function LockBoundControls(frm As Form, bLock As Boolean, ParamArray
avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form any
its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to lock
(variant array of strings).
'Usage: Call LockBoundControls(Me. True)
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
 
K

Ken Snell \(MVP\)

It shouldn't make any difference but try changing this line
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

to this
frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

If that doesn't work, then my conclusion is that the "frm" object that
you're using does not contain a command button named cmdLock. Check
carefully the Name property of the command button and verify that it is
named correctly.

--

Ken Snell
<MS ACCESS MVP>


jtb3 said:
Good morning, Reading this discussion group's threads made me aware of
Allen
Browne's very informative website. I have tried to implement his program
for
locking bound controls on a test form and subform
(http://allenbrowne.com/ser-56.html). I have created a tblTest with a PK
composed of an AutoNumber and a TestID; there is also a field [Vendor] in
the
table. I then created a table for the subform with a FK = TestID (linked
to
PK Master/Child and whose "Visible" attribute = False) and a field for
[Group]. All of these fields are formatted as text with the exception of
the
AutoNumber field. The mainform, formTest, contains a bound text box
[TestID],
a bound combo box [Vendor], and a command button 'Lock/Unlock'. I then
inserted a TabCtrl on the form to add the subform. Mr Browne's program
works
well to this point. As soon as I add a subform (with a bound text box
[TestID] and a bound combo box [Group]) the program gives the error 2465 -
Application-defined or Object-defined error and the command button does
not
change but remains fixed in the 'Lock' mode with the red rectangle
(indicating a locked record) visible. Originally if the red rectangle was
visible, the command button showed "Unlock" which allowed access for
edits/data entry. The line of code that gives the error is in this
Function
(abbreviated to save space):

Public Function LockBoundControls(frm As Form, bLock As Boolean,
ParamArray
avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form any
its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to lock
(variant array of strings).
'Usage: Call LockBoundControls(Me. True)
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
.
.
.
.
'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ** error line **
frm!rctLock.Visible = bLock

At this point, the variable bLock = True.

I have tried inserting the subform both manually and with the Wizard, I
have
placed the command button both in the form and on a Form Header all to no
avail; the source object for the subform is a query linking the tblTest2
to
tblTest. The only code behind the forms is that from Mr Browne's program.
I'm certain the error is a result of something I've either done or not
done
but I'm unable to find and correct it.

Any thoughts or help would be greatly appreciated. Thank you in advance.
 
J

jtb3

Ken,

Thank you for your response. As you surmised, changing the dot (.) to a
bang (!) did not make a difference [ frm.cmdLock.Caption = IIf(bLock,
"Un&lock", "&Lock")
to this frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ]. The only
command button on the form is cmdLock and it seems to be named correctly.
The program works as it is supposed to until I place a subform in the
TabControl on the MainForm. I've tried to make the test subform as simple as
possible but am unable to find the problem. By the way, I am using Access
2003 on a XP Pro system.

Thanks again for your time and insight.
--
John


Ken Snell (MVP) said:
It shouldn't make any difference but try changing this line
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

to this
frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

If that doesn't work, then my conclusion is that the "frm" object that
you're using does not contain a command button named cmdLock. Check
carefully the Name property of the command button and verify that it is
named correctly.

--

Ken Snell
<MS ACCESS MVP>


jtb3 said:
Good morning, Reading this discussion group's threads made me aware of
Allen
Browne's very informative website. I have tried to implement his program
for
locking bound controls on a test form and subform
(http://allenbrowne.com/ser-56.html). I have created a tblTest with a PK
composed of an AutoNumber and a TestID; there is also a field [Vendor] in
the
table. I then created a table for the subform with a FK = TestID (linked
to
PK Master/Child and whose "Visible" attribute = False) and a field for
[Group]. All of these fields are formatted as text with the exception of
the
AutoNumber field. The mainform, formTest, contains a bound text box
[TestID],
a bound combo box [Vendor], and a command button 'Lock/Unlock'. I then
inserted a TabCtrl on the form to add the subform. Mr Browne's program
works
well to this point. As soon as I add a subform (with a bound text box
[TestID] and a bound combo box [Group]) the program gives the error 2465 -
Application-defined or Object-defined error and the command button does
not
change but remains fixed in the 'Lock' mode with the red rectangle
(indicating a locked record) visible. Originally if the red rectangle was
visible, the command button showed "Unlock" which allowed access for
edits/data entry. The line of code that gives the error is in this
Function
(abbreviated to save space):

Public Function LockBoundControls(frm As Form, bLock As Boolean,
ParamArray
avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form any
its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to lock
(variant array of strings).
'Usage: Call LockBoundControls(Me. True)
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
.
.
.
.
'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ** error line **
frm!rctLock.Visible = bLock

At this point, the variable bLock = True.

I have tried inserting the subform both manually and with the Wizard, I
have
placed the command button both in the form and on a Form Header all to no
avail; the source object for the subform is a query linking the tblTest2
to
tblTest. The only code behind the forms is that from Mr Browne's program.
I'm certain the error is a result of something I've either done or not
done
but I'm unable to find and correct it.

Any thoughts or help would be greatly appreciated. Thank you in advance.
 
K

Ken Snell \(MVP\)

Check to be sure that your code is passing the correct object as the "frm"
variable to the subroutine.

--

Ken Snell
<MS ACCESS MVP>


jtb3 said:
Ken,

Thank you for your response. As you surmised, changing the dot (.) to a
bang (!) did not make a difference [ frm.cmdLock.Caption = IIf(bLock,
"Un&lock", "&Lock")
to this frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ]. The only
command button on the form is cmdLock and it seems to be named correctly.
The program works as it is supposed to until I place a subform in the
TabControl on the MainForm. I've tried to make the test subform as simple
as
possible but am unable to find the problem. By the way, I am using Access
2003 on a XP Pro system.

Thanks again for your time and insight.
--
John


Ken Snell (MVP) said:
It shouldn't make any difference but try changing this line
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

to this
frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

If that doesn't work, then my conclusion is that the "frm" object that
you're using does not contain a command button named cmdLock. Check
carefully the Name property of the command button and verify that it is
named correctly.

--

Ken Snell
<MS ACCESS MVP>


jtb3 said:
Good morning, Reading this discussion group's threads made me aware of
Allen
Browne's very informative website. I have tried to implement his
program
for
locking bound controls on a test form and subform
(http://allenbrowne.com/ser-56.html). I have created a tblTest with a
PK
composed of an AutoNumber and a TestID; there is also a field [Vendor]
in
the
table. I then created a table for the subform with a FK = TestID
(linked
to
PK Master/Child and whose "Visible" attribute = False) and a field for
[Group]. All of these fields are formatted as text with the exception
of
the
AutoNumber field. The mainform, formTest, contains a bound text box
[TestID],
a bound combo box [Vendor], and a command button 'Lock/Unlock'. I
then
inserted a TabCtrl on the form to add the subform. Mr Browne's program
works
well to this point. As soon as I add a subform (with a bound text box
[TestID] and a bound combo box [Group]) the program gives the error
2465 -
Application-defined or Object-defined error and the command button does
not
change but remains fixed in the 'Lock' mode with the red rectangle
(indicating a locked record) visible. Originally if the red rectangle
was
visible, the command button showed "Unlock" which allowed access for
edits/data entry. The line of code that gives the error is in this
Function
(abbreviated to save space):

Public Function LockBoundControls(frm As Form, bLock As Boolean,
ParamArray
avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form
any
its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to lock
(variant array of strings).
'Usage: Call LockBoundControls(Me. True)
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
.
.
.
.
'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ** error line
**
frm!rctLock.Visible = bLock

At this point, the variable bLock = True.

I have tried inserting the subform both manually and with the Wizard, I
have
placed the command button both in the form and on a Form Header all to
no
avail; the source object for the subform is a query linking the
tblTest2
to
tblTest. The only code behind the forms is that from Mr Browne's
program.
I'm certain the error is a result of something I've either done or not
done
but I'm unable to find and correct it.

Any thoughts or help would be greatly appreciated. Thank you in
advance.
 
J

jtb3

Ken,

I took the test program from my work computer and ran it on my home
computer without any problems at all. Both machines are identically
configured (I think). Unfortunately the final program has to run in the
office, so I'll be examining this new part of the puzzle.

Thanks again for your time and insight. It was much appreciated.
--
John


Ken Snell (MVP) said:
Check to be sure that your code is passing the correct object as the "frm"
variable to the subroutine.

--

Ken Snell
<MS ACCESS MVP>


jtb3 said:
Ken,

Thank you for your response. As you surmised, changing the dot (.) to a
bang (!) did not make a difference [ frm.cmdLock.Caption = IIf(bLock,
"Un&lock", "&Lock")
to this frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ]. The only
command button on the form is cmdLock and it seems to be named correctly.
The program works as it is supposed to until I place a subform in the
TabControl on the MainForm. I've tried to make the test subform as simple
as
possible but am unable to find the problem. By the way, I am using Access
2003 on a XP Pro system.

Thanks again for your time and insight.
--
John


Ken Snell (MVP) said:
It shouldn't make any difference but try changing this line
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

to this
frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

If that doesn't work, then my conclusion is that the "frm" object that
you're using does not contain a command button named cmdLock. Check
carefully the Name property of the command button and verify that it is
named correctly.

--

Ken Snell
<MS ACCESS MVP>


Good morning, Reading this discussion group's threads made me aware of
Allen
Browne's very informative website. I have tried to implement his
program
for
locking bound controls on a test form and subform
(http://allenbrowne.com/ser-56.html). I have created a tblTest with a
PK
composed of an AutoNumber and a TestID; there is also a field [Vendor]
in
the
table. I then created a table for the subform with a FK = TestID
(linked
to
PK Master/Child and whose "Visible" attribute = False) and a field for
[Group]. All of these fields are formatted as text with the exception
of
the
AutoNumber field. The mainform, formTest, contains a bound text box
[TestID],
a bound combo box [Vendor], and a command button 'Lock/Unlock'. I
then
inserted a TabCtrl on the form to add the subform. Mr Browne's program
works
well to this point. As soon as I add a subform (with a bound text box
[TestID] and a bound combo box [Group]) the program gives the error
2465 -
Application-defined or Object-defined error and the command button does
not
change but remains fixed in the 'Lock' mode with the red rectangle
(indicating a locked record) visible. Originally if the red rectangle
was
visible, the command button showed "Unlock" which allowed access for
edits/data entry. The line of code that gives the error is in this
Function
(abbreviated to save space):

Public Function LockBoundControls(frm As Form, bLock As Boolean,
ParamArray
avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form
any
its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to lock
(variant array of strings).
'Usage: Call LockBoundControls(Me. True)
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
.
.
.
.
'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ** error line
**
frm!rctLock.Visible = bLock

At this point, the variable bLock = True.

I have tried inserting the subform both manually and with the Wizard, I
have
placed the command button both in the form and on a Form Header all to
no
avail; the source object for the subform is a query linking the
tblTest2
to
tblTest. The only code behind the forms is that from Mr Browne's
program.
I'm certain the error is a result of something I've either done or not
done
but I'm unable to find and correct it.

Any thoughts or help would be greatly appreciated. Thank you in
advance.
 
K

Ken Snell \(MVP\)

The difference between home and office suggests that the two environments
are not the same. Be sure that the office software is patched/updated to the
same level as your home system. Also that the Windows software are
patched/updated the same.

--

Ken Snell
<MS ACCESS MVP>


jtb3 said:
Ken,

I took the test program from my work computer and ran it on my home
computer without any problems at all. Both machines are identically
configured (I think). Unfortunately the final program has to run in the
office, so I'll be examining this new part of the puzzle.

Thanks again for your time and insight. It was much appreciated.
--
John


Ken Snell (MVP) said:
Check to be sure that your code is passing the correct object as the
"frm"
variable to the subroutine.

--

Ken Snell
<MS ACCESS MVP>


jtb3 said:
Ken,

Thank you for your response. As you surmised, changing the dot (.)
to a
bang (!) did not make a difference [ frm.cmdLock.Caption = IIf(bLock,
"Un&lock", "&Lock")
to this frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ]. The
only
command button on the form is cmdLock and it seems to be named
correctly.
The program works as it is supposed to until I place a subform in the
TabControl on the MainForm. I've tried to make the test subform as
simple
as
possible but am unable to find the problem. By the way, I am using
Access
2003 on a XP Pro system.

Thanks again for your time and insight.
--
John


:

It shouldn't make any difference but try changing this line
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

to this
frm!cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")

If that doesn't work, then my conclusion is that the "frm" object that
you're using does not contain a command button named cmdLock. Check
carefully the Name property of the command button and verify that it
is
named correctly.

--

Ken Snell
<MS ACCESS MVP>


Good morning, Reading this discussion group's threads made me aware
of
Allen
Browne's very informative website. I have tried to implement his
program
for
locking bound controls on a test form and subform
(http://allenbrowne.com/ser-56.html). I have created a tblTest with
a
PK
composed of an AutoNumber and a TestID; there is also a field
[Vendor]
in
the
table. I then created a table for the subform with a FK = TestID
(linked
to
PK Master/Child and whose "Visible" attribute = False) and a field
for
[Group]. All of these fields are formatted as text with the
exception
of
the
AutoNumber field. The mainform, formTest, contains a bound text box
[TestID],
a bound combo box [Vendor], and a command button 'Lock/Unlock'. I
then
inserted a TabCtrl on the form to add the subform. Mr Browne's
program
works
well to this point. As soon as I add a subform (with a bound text
box
[TestID] and a bound combo box [Group]) the program gives the error
2465 -
Application-defined or Object-defined error and the command button
does
not
change but remains fixed in the 'Lock' mode with the red rectangle
(indicating a locked record) visible. Originally if the red
rectangle
was
visible, the command button showed "Unlock" which allowed access for
edits/data entry. The line of code that gives the error is in this
Function
(abbreviated to save space):

Public Function LockBoundControls(frm As Form, bLock As Boolean,
ParamArray
avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the
form
any
its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to lock
(variant array of strings).
'Usage: Call LockBoundControls(Me. True)
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
.
.
.
.
'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock") ** error
line
**
frm!rctLock.Visible = bLock

At this point, the variable bLock = True.

I have tried inserting the subform both manually and with the
Wizard, I
have
placed the command button both in the form and on a Form Header all
to
no
avail; the source object for the subform is a query linking the
tblTest2
to
tblTest. The only code behind the forms is that from Mr Browne's
program.
I'm certain the error is a result of something I've either done or
not
done
but I'm unable to find and correct it.

Any thoughts or help would be greatly appreciated. Thank you in
advance.
 

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