From: Kelly on
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
From: BruceM via AccessMonster.com on
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?


Kelly wrote:
>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

--
Message posted via http://www.accessmonster.com