473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Lock a field on specific records in a subform

WyvsEyeView
I have a dataset subform on which I want to lock a field for just two specific records. Each record has a type_id and a desc field. I want to test the value of the type_id field for the current record and if it is "PROD" or "LIBR" I want to lock the field. (I can allow editing of the desc field.) type_id field for all other records should remain unlocked. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub type_id_Enter()
  2.   If Me.type_id.Value = "PROD" Then
  3.     Me.type_id.Locked = True
  4.     MsgBox "You cannot edit this type.", vbOKOnly
  5.   Else
  6.     Me.type_id.Locked = False
  7.   End If
  8.   If Me.type_id.Value = "LIBR" Then
  9.     Me.type_id.Locked = True
  10.     MsgBox "You cannot edit this type.", vbOKOnly
  11.   Else
  12.     Me.type_id.Locked = False
  13.   End If
  14. End Sub
The message box is displaying correctly but I can still edit the PROD or LIBR records after dismissing the box. I have also tried this code with the OnCurrent and BeforeUpdate events, with even less success. Thanks for any advice.
Jul 28 '08 #1
1 3598
missinglinq
3,532 Expert 2GB
I only had the problem when the id_Type was PROD, which is even curioser. I modified the code slightly, placing parts in Form_Current and part in the id_Type.Enter event, and it works fine. I would add a line, at the very beggining, in the Form_Current event, setting the initial focus to another control. It will be very irritating to users, and possibly confusing, to have the message pop up when they move to the record and before they'd done anything. This way it will only chastise them if they deliberately move into the field that has PROD or LIBR in it. It will also help to educate them.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me.type_id.Value = "PROD" Or Me.type_id.Value = "LIBR" Then
  3.  Me.type_id.Locked = True
  4. Else
  5.  Me.type_id.Locked = False
  6. End If
  7. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub type_id_Enter()
  2. If Me.type_id.Value = "PROD" Or Me.type_id.Value = "LIBR" Then
  3.  MsgBox "You cannot edit this type.", vbOKOnly
  4. End If
  5. End Sub
Welcome to Bytes!

Linq ;0)>
Jul 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: William Wisnieski | last post by:
Hello Again, I'm really stuck on this one.....so I'm going to try a different approach to this problem. I have a query by form that returns a record set in a datasheet. The user double...
2
by: Michelle | last post by:
Hi all I have used knowledge base article 112747 to improve my subforms performance. I am using Access 97. I have a main form where i put an extra textbox which concatenated TeamID WeekNum...
3
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
7
by: Saintor | last post by:
What I do now is I put a value in the tag property, and using the form_current event, I run through all controls properties until the ones with the required tag value are met. Sound OK in theory,...
1
by: sasan3 | last post by:
Well, I have the lock part figured out.. but how do I gray-out or put in some type of visual effect that indicated that the row in the subform is locked? Thanks. Si
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
3
by: JML | last post by:
How do I able to locked users from pasting records from column datasheet to another column? My case is I have a form that has a check box that determines when it is checked, the subform datasheet...
2
by: austris | last post by:
Hi, It's single user .mdb (for now). i've created a generic form for a user to add a note to existing note in a memo Note field in a table (myTbl). The relevant part of the code: ' NoteText...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.