Unlock text box for new record entry

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
 
M

Marshall Barton

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
 
A

anlu

Hi,

Put your code in the Form's Current event - that should do the trick.

Regards,
anlu
 
H

h2fcell

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. :)
 

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