How selectively lock records from editing?

S

Silvio

In my case, I have a form with a subform. The subform was populated by a
query. User should be able to view and enter new records but should not be
able to edit existing records. Each record has several fields; the important
one is [Rate] and [Type]. If data is entered in [Rate] and [Type] then that
record or these two fields should be locked for editing.

I tried to do something like this…
I did this by adding VB code to the LostFocus() event of [Type] field.

Private Sub Charge_Type_LostFocus()
If Not IsNull(Me.Rate) and Not isNull(me.Type) Then
Me.Rate.Enabled = False
Me.Type.Enabled = False
End If
End Sub

As you can expect, this will lock all the record in the list including the
ability to enter new records from the bottom of the list. Id there any
relatively simple way to handle this?
 
A

Arvin Meyer [MVP]

That's what else is for, and I'd use it in the form's Current event:

Private Sub Form_Current()
If Not IsNull(Me.Rate) and Not IsNull(Me.Type) Then
Me.Rate.Enabled = False
Me.Type.Enabled = False
Else
Me.Rate.Enabled = True
Me.Type.Enabled = True
End If
End Sub
 
S

Silvio

Arvin thank you for you response, however still dosent work. All the records
are locked and when I try to add a new record I can not click on the Rate
field in order to start to create a new record. When a click on a different
filed of the same raw then all the records are unlocked even though the
re-lock if I try to make modifications. Any idea?

Arvin Meyer said:
That's what else is for, and I'd use it in the form's Current event:

Private Sub Form_Current()
If Not IsNull(Me.Rate) and Not IsNull(Me.Type) Then
Me.Rate.Enabled = False
Me.Type.Enabled = False
Else
Me.Rate.Enabled = True
Me.Type.Enabled = True
End If
End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Silvio said:
In my case, I have a form with a subform. The subform was populated by a
query. User should be able to view and enter new records but should not be
able to edit existing records. Each record has several fields; the
important
one is [Rate] and [Type]. If data is entered in [Rate] and [Type] then
that
record or these two fields should be locked for editing.

I tried to do something like this.
I did this by adding VB code to the LostFocus() event of [Type] field.

Private Sub Charge_Type_LostFocus()
If Not IsNull(Me.Rate) and Not isNull(me.Type) Then
Me.Rate.Enabled = False
Me.Type.Enabled = False
End If
End Sub

As you can expect, this will lock all the record in the list including the
ability to enter new records from the bottom of the list. Id there any
relatively simple way to handle this?
 
A

Arvin Meyer [MVP]

I may not have understood. To lock existing records, you can adjust the
form's property sheet.

On the property sheet data tab turn off Allow Editing and Allow Deletions,
and leave Allow Additions on. No code at all. Existing records cannot be
edited or deleted, and new ones can be added.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Silvio said:
Arvin thank you for you response, however still dosent work. All the
records
are locked and when I try to add a new record I can not click on the Rate
field in order to start to create a new record. When a click on a
different
filed of the same raw then all the records are unlocked even though the
re-lock if I try to make modifications. Any idea?

Arvin Meyer said:
That's what else is for, and I'd use it in the form's Current event:

Private Sub Form_Current()
If Not IsNull(Me.Rate) and Not IsNull(Me.Type) Then
Me.Rate.Enabled = False
Me.Type.Enabled = False
Else
Me.Rate.Enabled = True
Me.Type.Enabled = True
End If
End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Silvio said:
In my case, I have a form with a subform. The subform was populated by
a
query. User should be able to view and enter new records but should not
be
able to edit existing records. Each record has several fields; the
important
one is [Rate] and [Type]. If data is entered in [Rate] and [Type] then
that
record or these two fields should be locked for editing.

I tried to do something like this.
I did this by adding VB code to the LostFocus() event of [Type] field.

Private Sub Charge_Type_LostFocus()
If Not IsNull(Me.Rate) and Not isNull(me.Type) Then
Me.Rate.Enabled = False
Me.Type.Enabled = False
End If
End Sub

As you can expect, this will lock all the record in the list including
the
ability to enter new records from the bottom of the list. Id there any
relatively simple way to handle this?
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 

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