Grey out Fields

sondriven

Registered User.
Local time
Today, 10:02
Joined
Jun 13, 2002
Messages
158
Hi, Im wanting to make a couple of text fields uneditable after data is put into them. Im kinda lost on how to do this.

I want to avoid someone changing data in these fields.

Thanks.
 
Private Sub LockControls()

Dim txtOne as textbox

Set txtOne=Me!txtbox1

If Not IsNull(txtOne) Then
txtOne.Locked=True
End If

End Sub

I would use this if I only needed to lock one textbox and set this sub in the "On Current" event of the form.

If you have many that you need to lock it would be best if you used a For Each... Next statement to loop through them all. And I'm not to experienced at those yet.

Anyone have a suggestion on that?
 
Hi

I did a sort of similar thing on an address field.

I put this code in the "OnCurrent" event of the form so that it runs everytime a record is viewed.

If IsNull(Me.Addr_1) Then
Me.Addr_1.Locked = False
Me.Addr_2.Locked = False
Me.Addr_3.Locked = False
Me.Addr_4.Locked = False
Else
Me.Addr_1.Locked = True
Me.Addr_2.Locked = True
Me.Addr_3.Locked = True
Me.Addr_4.Locked = True
End If

What this does is checks if something is in it, if it is then the field is locked. If not then its ready for text to be added.

Hope this helps
Col
:cool:

Edit - Rob, we posted at the same time!!!
 
Add this code to your form:

Code:
'Add this code to lock the fields when you move record to record.
Private Sub Form_Current()
    Call LockFields
End Sub

'Add this for each text box to lock it after data is initally entered.
'Do not add this code to each field if you want to allow them to 
'Edit the data and have the locks in place after they have gone
'to a new record.

Private Sub txtField1_AfterUpdate()
   Call LockFields
End Sub

Private Sub LockFields()
'Add each field you want to lock here.
   txtField1.Locked=(Nz(txtField1,"")<>"") 'If txtField has data this evaluates to True, when it doesn't have data it evaluates to false.
End Sub
 

Users who are viewing this thread

Back
Top Bottom