473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lock a field on specific records in a subform

WyvsEyeView
46 New Member
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 3618
missinglinq
3,532 Recognized Expert Specialist
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
14502
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 clicks on a row and a main form (pop up) opens bound to a table with a continuous subform bound to another table. On the main form is a field called . ...
2
5764
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 Weekday, ie value might be 15Monday. I then put in a field in my query behind my subform which held the same info and used these fields to link the...
3
579
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 make a query that selects from a table as desribed below .. I have a table (Volunteer) that has a member field (memnumber) and a number of fields ...
25
10184
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 data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab...
7
9806
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, but it is ... slow. I thought having a table with the name, type of controls and put my 'tag value' there. At the opening of the form, I would...
1
2644
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
9674
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 master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
3
3726
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 will be locked from users to edit, otherwise they can edit. I done this by locking each field in the subform successfully, but I also want the fields...
2
2597
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 = ExsntNote & Chr(13) & Chr(10) & Date & " (" & GetUserName & ") " & NoteText
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.