conditional field lock

R

Ralph

I want to lock several fields on a form using the ‘On Open’ event and
conditional locking that is dependent on the value in another field.

Something like,
If a field named ‘Strata’ is equal to “4†then lock three fields named
‘ClaimsCount’, ‘Claims$’, and ‘ClaimsCorrect’ so that data cannot be entered
in them. The locked fields will be null values.

When the form closes I'd like to unlock the fields.

Thanks much,
Ralph
 
A

Al Campagna

Ralph,
Locking or unlocking controls using the OnOpen event would
work on the first record displayed, but not as you move from
record to record.
I would suggest using the AfterUpdate event of Strata
If [Strata] = 4 Then
ClaimsCount.Locked = True
Claims$.Locked = True
ClaimsCorrect.Locked = True
Else
ClaimsCount.Locked = False
Claims$.Locked = False
ClaimsCorrect.Locked = False
End If

That takes care of Strata having a 4 entered.
Use the very same code in the OnCurrent event of your form.
When the form opens, as you browse from record to record, those
controls will lock/unlock correctly.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
R

Ralph

I get a compile error highlighting the ‘.Locked =’ portion of the code :
“Method or data member not foundâ€
I should say I am running Access 2007 if that matters.
What I find is that I can build the first .lock portion and can’t just paste
in the script. Then it works. But the next field doesn’t give me the
‘locked’ choice. All I get is ‘value’ as a choice and if I type in ‘locked’
then I get the error message again when I compile. All I am able to lock is
one field.
Private Sub Form_Open(Cancel As Integer)
If [Stratum] = 4 Then
ClaimsCount.Locked = False
UPmnt.Value
Else
ClaimsCount.Locked = True
UPmnt.Value
End If
Thank you. Because the form is used for only one record at a time and
closed between accessing records, the ‘On Open’ event would seem to me to be
okay to use. The form has tabs if that makes a difference
 
A

Al Campagna

Ralph,
Whenever you have trouble with code, cut and paste it exactly
as you have it, into your reply.
The syntax...
[SomeTextControlName].Locked = True
or
[SomeTextControlName].Locked = False
Is legitimate. I assumed that the code is called from an event on
the main form, and refers to a text control on the main form.

What types of controls are the other 2 controls.
What are they named, and what are the ControlSources
If they are bound, describe the bound field's properties from your
table design.
-------------------
the form is used for only one record at a time and
closed between accessing records...

There's no rule against that, but it would be more productive to have
a quick find combo box that would let you move from one record to
another during the editing process.
On my website (below), I have a sample 97 or 2003 sample file
called Combo Quick Find. It allows the user to edit a record, jump to
another record (by user combo selection)... edit that record.. etc.. etc...
Your call on that...
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."


Ralph said:
I get a compile error highlighting the '.Locked =' portion of the code :
"Method or data member not found"
I should say I am running Access 2007 if that matters.
What I find is that I can build the first .lock portion and can't just
paste
in the script. Then it works. But the next field doesn't give me the
'locked' choice. All I get is 'value' as a choice and if I type in
'locked'
then I get the error message again when I compile. All I am able to lock
is
one field.
Private Sub Form_Open(Cancel As Integer)
If [Stratum] = 4 Then
ClaimsCount.Locked = False
UPmnt.Value
Else
ClaimsCount.Locked = True
UPmnt.Value
End If
Thank you. Because the form is used for only one record at a time and
closed between accessing records, the 'On Open' event would seem to me to
be
okay to use. The form has tabs if that makes a difference


Ralph said:
I want to lock several fields on a form using the 'On Open' event and
conditional locking that is dependent on the value in another field.

Something like,
If a field named 'Strata' is equal to "4" then lock three fields named
'ClaimsCount', 'Claims$', and 'ClaimsCorrect' so that data cannot be
entered
in them. The locked fields will be null values.

When the form closes I'd like to unlock the fields.

Thanks much,
Ralph
 
R

Ralph

Thank you for your help. I was unable to make the tabbed form hide fields
beyond the first two and gave up. As a work around I created a subform and
was able to make the visible or not depending on the value in the Strata
field. Thank you again your help is quite valuable.

Ralph

Al Campagna said:
Ralph,
Whenever you have trouble with code, cut and paste it exactly
as you have it, into your reply.
The syntax...
[SomeTextControlName].Locked = True
or
[SomeTextControlName].Locked = False
Is legitimate. I assumed that the code is called from an event on
the main form, and refers to a text control on the main form.

What types of controls are the other 2 controls.
What are they named, and what are the ControlSources
If they are bound, describe the bound field's properties from your
table design.
-------------------
the form is used for only one record at a time and
closed between accessing records...

There's no rule against that, but it would be more productive to have
a quick find combo box that would let you move from one record to
another during the editing process.
On my website (below), I have a sample 97 or 2003 sample file
called Combo Quick Find. It allows the user to edit a record, jump to
another record (by user combo selection)... edit that record.. etc.. etc...
Your call on that...
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."


Ralph said:
I get a compile error highlighting the '.Locked =' portion of the code :
"Method or data member not found"
I should say I am running Access 2007 if that matters.
What I find is that I can build the first .lock portion and can't just
paste
in the script. Then it works. But the next field doesn't give me the
'locked' choice. All I get is 'value' as a choice and if I type in
'locked'
then I get the error message again when I compile. All I am able to lock
is
one field.
Private Sub Form_Open(Cancel As Integer)
If [Stratum] = 4 Then
ClaimsCount.Locked = False
UPmnt.Value
Else
ClaimsCount.Locked = True
UPmnt.Value
End If
Thank you. Because the form is used for only one record at a time and
closed between accessing records, the 'On Open' event would seem to me to
be
okay to use. The form has tabs if that makes a difference


Ralph said:
I want to lock several fields on a form using the 'On Open' event and
conditional locking that is dependent on the value in another field.

Something like,
If a field named 'Strata' is equal to "4" then lock three fields named
'ClaimsCount', 'Claims$', and 'ClaimsCorrect' so that data cannot be
entered
in them. The locked fields will be null values.

When the form closes I'd like to unlock the fields.

Thanks much,
Ralph
 
A

Al Campagna

Ralph,
Text Controls that are located on a tab, not in a subform on the tab,
but on the tab page iteself... are considered to be on the Main form...
as regards "addressing" their properties.
Me.Somefield would be a legitimate address if the control
was located on the main form, OR... if the control was on any tab page
on that main form.

**There should be no reason to create a subform to make a control
on a form Locked or Unlocked.**

There is definitely some problem with your initial setup.
Sorry that you don't want to persue the original problem.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

Ralph said:
Thank you for your help. I was unable to make the tabbed form hide fields
beyond the first two and gave up. As a work around I created a subform
and
was able to make the visible or not depending on the value in the Strata
field. Thank you again your help is quite valuable.

Ralph

Al Campagna said:
Ralph,
Whenever you have trouble with code, cut and paste it exactly
as you have it, into your reply.
The syntax...
[SomeTextControlName].Locked = True
or
[SomeTextControlName].Locked = False
Is legitimate. I assumed that the code is called from an event on
the main form, and refers to a text control on the main form.

What types of controls are the other 2 controls.
What are they named, and what are the ControlSources
If they are bound, describe the bound field's properties from your
table design.
-------------------
the form is used for only one record at a time and
closed between accessing records...

There's no rule against that, but it would be more productive to have
a quick find combo box that would let you move from one record to
another during the editing process.
On my website (below), I have a sample 97 or 2003 sample file
called Combo Quick Find. It allows the user to edit a record, jump to
another record (by user combo selection)... edit that record.. etc..
etc...
Your call on that...
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your
life."


Ralph said:
I get a compile error highlighting the '.Locked =' portion of the code :
"Method or data member not found"
I should say I am running Access 2007 if that matters.
What I find is that I can build the first .lock portion and can't just
paste
in the script. Then it works. But the next field doesn't give me the
'locked' choice. All I get is 'value' as a choice and if I type in
'locked'
then I get the error message again when I compile. All I am able to
lock
is
one field.
Private Sub Form_Open(Cancel As Integer)
If [Stratum] = 4 Then
ClaimsCount.Locked = False
UPmnt.Value
Else
ClaimsCount.Locked = True
UPmnt.Value
End If
Thank you. Because the form is used for only one record at a time and
closed between accessing records, the 'On Open' event would seem to me
to
be
okay to use. The form has tabs if that makes a difference


:

I want to lock several fields on a form using the 'On Open' event and
conditional locking that is dependent on the value in another field.

Something like,
If a field named 'Strata' is equal to "4" then lock three fields named
'ClaimsCount', 'Claims$', and 'ClaimsCorrect' so that data cannot be
entered
in them. The locked fields will be null values.

When the form closes I'd like to unlock the fields.

Thanks much,
Ralph
 

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