Locking lookup fields in form

rdev

Registered User.
Local time
Today, 21:22
Joined
Mar 2, 2009
Messages
18
I have a table named tblShipmaster with fields
IMO_Num(Primarykey),Ship_Name,Vessel_type.
The Vessel_type field picks up value from a lookup field of a table called tblshipcategory
I have a related form to enter data in the tblShipmaster, the form is known as frmshipmaster.
After a few records are entered directly in the table . I go to the form frmshipmaster to enter few other records. However, in the form I can edit the field Vessel_type , this should not be possible for records I have already entered. when I am picking this field (Vessel_type) in other queries , I can edit the field for the related record. I should not be able to do this . How can I lock this

Thanks\
Dev
 
When you open a table or query, you can edit data. If you want to be able to lock control from being edited, you should always use a form for data entry.

You can use a form's On Current event to lock control for existing records.

Simple example:

Code:
Private Sub Form_Current()


If Me.NewRecord Then
  Me.txtMyControlName.Locked = False

Else
   Me.txtMyControlName.Locked = True

End If
 
Thanks
But when I open the form , I can edit the previously entered data, so a user can change my previously entered data. how can I stop this
 
Thanks for the code , but how do I integrate it in the database, I really new and do not know how to handle macros currently
 
If you want to lock a record, not jsut some controls then try:

Code:
Private Sub Form_Current()

If Me.NewRecord Then
  Me.AllowEdits = True

Else
   Me.AllowEdits = False

End If

End Sub

or


Code:
Private Sub Form_Current()

  Me.AllowEdits = Me.NewRecord

End Sub


Both will work. The second version is just more concise and might be harder to read/understand.
 

Users who are viewing this thread

Back
Top Bottom