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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lock a specific field on a new record only using Access 2003

Status
Not open for further replies.

ans303

Technical User
Jan 24, 2009
5
I want to lock a specific field on a new record using Access 2003. The name of the field is DO Staff. DO Staff is a combo box. I want to lock DO Staff on a new record so it cannot be changed after it is saved. What is happening is after I do this one time DO Staff is locked for all subsequent records. I want the ability to select DO staff on each new record, then save and lock it as to that record only, and so on.

I am trying to accomplish this by using the following:

Private Sub DO_Staff_AfterUpdate()

If Form.DO_Staff.Locked = False Then
Form.DO_Staff.Locked = True

End If

End Sub

I can see where this locks DO Field.

Then I am using the following to be able to repeat this on each new record, and it is not working:

Private Sub Form_Current()

If Me.NewRecord Or IsNull(Me!DO_Staff.Value) Then
Me.DO_Staff.Locked = False

End If

End Sub


It doesn't like

If Me.NewRecord Or IsNull(Me!DO_Staff.Value) Then


and turns it yellow.

Please make a recommendation how to accomplish this. I appreciate any comments.

Thanks.

 

This will lock the combobox if it has already had a selection made, otherwise it'll still be selectable:

Code:
Private Sub Form_Current()
If Not IsNull(Me!DO_Staff.Value) Then
 Me.DO_Staff.Locked = True
Else
 Me.DO_Staff.Locked = False
End If
End Sub


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thank you for responding. I appreciate it.

Do I leave the After Update Event on DO Staff?

It still seems to have problems and turns the second line yellow:

Private Sub Form_Current()

If Not IsNull(Me!DO_Staff.Value) Then

Me.DO_Staff.Locked = True

Else
Me.DO_Staff.Locked = False

End If

End Sub


An error box pops up which ways

Run Time Error '2465'. Microsoft Office Access can't find the field 'DO_Staff' referred to in your expression.

It's on the form as a combo box. Still confused.

Any further suggestions, please?


 
It seems to be working now. I drug down a new DO Staff Combo Box and started it over and it works. Thanks.
 
Glad you got it working!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
How are ya ans303 . . .

Welcome to [blue]Tek-Tips![/blue] [thumbsup2] Do have a look at one of the links at the bottom of my post. The links will help you [blue]ask better questions[/blue], get [blue]quick responses[/blue], [blue]better answers[/blue], and insite into [blue]etiquette[/blue] here in the forums. Again . . . Welcome to [blue]Tek-Tips![/blue] [thumbsup2] [blue]Its Worthy Reading![/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
This is working exactly as I asked, and now I realize it is too restrictive. How can I relax it to NOT lock until a certain amount of time has elapsed, for example, don't lock until five days from the add date?

I have a field called Add Date that is set to Now() as the default when you add a new record. Your help and time spend are much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top