Unlock text box for new record entry

  • Thread starter Thread starter h2fcell
  • Start date Start date
H

h2fcell

Help! I’m in need of a little assistance. Using Access 2007; I have a
form, frmAgents, that has five Text Boxes bound to fields in one table. The
form has the following property settings:
Record Selectors = No
Navigation Buttons = Yes
Allow Additions = Yes
Allow Deletion = No
Allow Edits = Yes

The user is not allowed to edit the first two text boxes by way of setting
their Locked property to Yes.
When the user needs to enter a new record the two Locked text boxes need to
be unlocked.
I have the following code to unlock the boxes but would like them to lock
again if the user navigates to an existing record. I think my code is under
the wrong event. Any suggestion of where I’m going wrong is appreciated.
My code doesn’t work when “New (blank) record†button is pressed in the
Navigation bar.

Private Sub tboCode_Dirty(Cancel As Integer)
Dim intnewrec As Integer

intnewrec = Form.NewRecord
If intnewrec = True Then
Me!tboCode.Locked = False
Me!tboAgent.Locked = False
Else
Me!tboCode.Locked = True
Me!tboAgent.Locked = True
End If

End Sub
 
h2fcell said:
Help! I’m in need of a little assistance. Using Access 2007; I have a
form, frmAgents, that has five Text Boxes bound to fields in one table. The
form has the following property settings:
Record Selectors = No
Navigation Buttons = Yes
Allow Additions = Yes
Allow Deletion = No
Allow Edits = Yes

The user is not allowed to edit the first two text boxes by way of setting
their Locked property to Yes.
When the user needs to enter a new record the two Locked text boxes need to
be unlocked.
I have the following code to unlock the boxes but would like them to lock
again if the user navigates to an existing record. I think my code is under
the wrong event. Any suggestion of where I’m going wrong is appreciated.
My code doesn’t work when “New (blank) record” button is pressed in the
Navigation bar.

Private Sub tboCode_Dirty(Cancel As Integer)
Dim intnewrec As Integer

intnewrec = Form.NewRecord
If intnewrec = True Then
Me!tboCode.Locked = False
Me!tboAgent.Locked = False
Else
Me!tboCode.Locked = True
Me!tboAgent.Locked = True
End If

End Sub


Use the form's Current event, not the dirty event.

The code could be shortened to just:

Me!tboCode.Locked = Not Me.NewRecord
Me!tboAgent.Locked = Not Me.NewRecord
 
Simple and elegant. Thanks very much, this works great. All I need to know
now is how many years will it take me to know the ins and outs like you do. :)
 
Back
Top