Lock fields in subform except two after authorization date is ente

K

Kelly

Need assistance from the experts. I used the following code to lock the
fields in a subform per a request. Now I have been request to lock all the
fields except two in the sub form and I am not sure how to handle this. I
tried enabled on the different fields but that did not correct the problem.
The goal is to enter data for that record and once an authorization date is
entered it would lock the record. Is there a way to allowedits and lock it
back if someone needs to change the field StructureKeymark? Thanks in advance
to assistance.

This is just a few lines for the main fields I'm trying to address

Option Compare Database
Private Sub StructureApprovedDate_Enter()
If IsNull([StructureApprovedDate]) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If
End Sub

Private Sub StructureKeymark_Enter()
If IsNull([StructureApprovedDate]) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If
End Sub

Kelly
 
K

Kelly

Thanks for the response but there is still a problem. The sub form contains
several controls. Once the data is entered into each of the controls another
department looks over what has been input then places a date in the
StructureApprovedDate control. This is what I was using as my If IsNull. At
this point I need all of the controls to be locked except the
StructureKeymark and FoundationKeymark for that record so the designer can
change those fields at all times. And have the ability to allow the designer
to add additional entries/records to that job. The LockCtls will not work for
what I need. Do you have another suggestion? Thanks....
Kelly


BruceM via AccessMonster.com said:
You lock controls, not fields. If you do not allow edits, I doubt it makes
any difference whether a control is locked (or enabled) or not.

Why not just lock controls other than the two, using the control properties?
Then make a function something like this:

Private Function LockCtls()

Me.Text1.Locked = Not IsNull(Me.txtAuthDate) And Not IsNull(Me.Text1)
Me.txtAuthDate.Locked = Me.Text1.Locked

End Function

In the After Update event of each of the two controls and in the form's
Current event:

Call LockCtls()

If you allow zero-length strings in the text field you may need to do:

Private Function LockCtls()

Me.Text1.Locked = Not IsNull(Me.txtAuthDate) And Nz(Me.Text1,"") = ""
Me.txtAuthDate.Locked = Me.Text1.Locked

End Function

I can't help wondering what the rest of the controls are that they need to be
locked all the time. Do they ever receive data?

Need assistance from the experts. I used the following code to lock the
fields in a subform per a request. Now I have been request to lock all the
fields except two in the sub form and I am not sure how to handle this. I
tried enabled on the different fields but that did not correct the problem.
The goal is to enter data for that record and once an authorization date is
entered it would lock the record. Is there a way to allowedits and lock it
back if someone needs to change the field StructureKeymark? Thanks in advance
to assistance.

This is just a few lines for the main fields I'm trying to address

Option Compare Database
Private Sub StructureApprovedDate_Enter()
If IsNull([StructureApprovedDate]) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If
End Sub

Private Sub StructureKeymark_Enter()
If IsNull([StructureApprovedDate]) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If
End Sub

Kelly
 
K

Kelly

You are correct.
Are you saying that somebody enters data into
some of the controls, after which all of the controls but two are locked?
Initial data entry then I was having the controls lock when a date was
entered into the StructureApprovedDate control. As far as validation none
were in place in the code. Not all of the fields would neccessarily have data
either.
Kelly


BruceM via AccessMonster.com said:
I'm not really following you. Are you saying that somebody enters data into
some of the controls, after which all of the controls but two are locked?

Maybe this will give you a way of doing what you need. All controls have a
Tag property. You can set the Tag to, say, L for a control that needs to be
locked. Then you could have a function like this in the form's code module:

Private Function LockControls

Dim ctl as Control

For Each ctl in Me.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.Locked = (ctl.Tag = "L")
End If
Next ctl

End Function

Call the function from the form's Current event, and wherever else you need
it.

List all of the control types that are used for data entry. You need to
specify the control type because some controls such as command buttons do not
have a Locked property, so Access will trip over them in the code.

That's all the detail I can provide without a better understanding of your
needs. It sounds as if somebody does the initial data entry, after which all
but two controls are locked. Is there any validation of the initial controls
in the form's Before Update event to assure all required controls are filled
in? That is, how does Access know it is time to lock all but two controls?
You may need to do something such as test a control before calling the
function. The function may end up something like this:

Dim ctl as Control
Dim blnAuth as Boolean

blnAuth = Not IsNull(Me.StructureApprovedDate)

For Each ctl in Me.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.Locked = (ctl.Tag = "L") And blnAuth = True
End If
Next ctl
Thanks for the response but there is still a problem. The sub form contains
several controls. Once the data is entered into each of the controls another
department looks over what has been input then places a date in the
StructureApprovedDate control. This is what I was using as my If IsNull. At
this point I need all of the controls to be locked except the
StructureKeymark and FoundationKeymark for that record so the designer can
change those fields at all times. And have the ability to allow the designer
to add additional entries/records to that job. The LockCtls will not work for
what I need. Do you have another suggestion? Thanks....
Kelly
You lock controls, not fields. If you do not allow edits, I doubt it makes
any difference whether a control is locked (or enabled) or not.
[quoted text clipped - 55 lines]
 
K

Kelly

When someone enters a date in the StructureApprovedDate control.

Kelly


BruceM via AccessMonster.com said:
If you disallow edits none of the controls can be edited. If you loop
through controls as I have shown you can selectively lock controls. You need
to decide the criteria that will cause controls to be locked. You say that
not all the controls would necessarily have data. OK, so how does Access
know when to lock the controls?
You are correct.
Are you saying that somebody enters data into
some of the controls, after which all of the controls but two are locked?
Initial data entry then I was having the controls lock when a date was
entered into the StructureApprovedDate control. As far as validation none
were in place in the code. Not all of the fields would neccessarily have data
either.
Kelly
I'm not really following you. Are you saying that somebody enters data into
some of the controls, after which all of the controls but two are locked?
[quoted text clipped - 57 lines]

--
Message posted via AccessMonster.com


.
 

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