Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locked field

Status
Not open for further replies.

jake7363

Technical User
May 31, 2006
56
Hello,
Is is it possible to lock a field in a form for a specific record after data is entered, without locking the field for all of the records?
What I am trying to do is not allow any changes to the data in that field, once the data is entered. But if there is no data in the field, I want to allow data entry.

Thanks in advance,
Jake
 
..sorry, forgot to add that it is a continuous form.
Thanks.
 
Well, you could try putting in a conditional statement in your code that says something like:

Code:
Private Sub Form_Dirty()
On Error GoTo ErrHandle
  If IsNull(txtMyTextBox) Then
    txtMyTextBox.Locked = False
    txtMyTextBox.Enabled = True
  Else
    txtMyTextBox.Locked = False
    txtMyTextBox.Enabled = True
  End If

Exit Sub

ErrHandle:
  MsgBox "We've got a problem!" & Chr(13) & Chr(13)& _
         "Error Number" & Chr(9) & "Error Description" & _
         Chr(13) & Err.Number & Chr(9) & Err.Description, vbCritical, _
         "Error!"
End Sub
 
[/code]
Private Sub Form_Current()
Dim ctrlName As String
'Put your control name here
ctrlName = "strMiddleInitial"
If Not Trim(Me.Controls(ctrlName) & " ") = "" Then
Me.Controls(ctrlName).Locked = True
Else
Me.Controls(ctrlName).Locked = False
End If

End Sub
[/code]
If Not Trim(Me.Controls(ctrlName) & " ") = "" Then
checks null
check empty string
checks space
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top