473,382 Members | 1,377 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,382 software developers and data experts.

How to lock a field in a record or make it read only

Hi, Im fairly new in the Access world. I would like to know how I can prevent users from changing data entered into a specific field of a record. Once I have completed the data Entry they should be able to see the information but not be able to change it.
Jul 18 '07 #1
11 49270
puppydogbuddy
1,923 Expert 1GB
Hi, Im fairly new in the Access world. I would like to know how I can prevent users from changing data entered into a specific field of a record. Once I have completed the data Entry they should be able to see the information but not be able to change it.
Here is one way, assuming that you are using a bound form for data entry:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Not Me.NewRecord Then
  3.    'Lock YourControl for each record.
  4.     Me!YourControl.Locked = True
  5. Else
  6.     Me!YourControl.Locked = False
  7. End If
  8. End Sub 
Jul 18 '07 #2
MikeTheBike
639 Expert 512MB
Hi
Here is one way, assuming that you are using a bound form for data entry:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Not Me.NewRecord Then
  3.    'Lock YourControl for each record.
  4.     Me!YourControl.Locked = True
  5. Else
  6.     Me!YourControl.Locked = False
  7. End If
  8. End Sub 
As an alternative is
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me.NewRecord Then
  3.     Me.AllowEdits = True
  4. Else
  5.     Me.AllowEdits = False
  6. End If
  7. End Sub 
You could also include
Me.AllowDeletions= ....
if you want to prevent record deletion also.


MTB
Jul 19 '07 #3
damonreid
114 Expert 100+
You could always just go into the Properties and change
Enabled = False
Locked = True

and ignore the VB side of it.
Jul 19 '07 #4
Thanks for the advise. I have used this code to lock all fields in current form. Once the first record is created the code doesn't allow any editing or deleting. The problem I have now is how to make changes to that record at a later time.
Any Additional advise will be highly appreciated

1. Private Sub Form_Current()
2. If Me.NewRecord Then
3. Me.AllowAdditions = True
4. Me.AllowDeletions = True
5. Me.AllowEdits = True
6. Else
7. Me.AllowAdditions = True
8. Me.AllowDeletions = False
9. Me.AllowEdits = False
10. End If
Jul 19 '07 #5
MikeTheBike
639 Expert 512MB
Thanks for the advise. I have used this code to lock all fields in current form. Once the first record is created the code doesn't allow any editing or deleting. The problem I have now is how to make changes to that record at a later time.
Any Additional advise will be highly appreciated

1. Private Sub Form_Current()
2. If Me.NewRecord Then
3. Me.AllowAdditions = True
4. Me.AllowDeletions = True
5. Me.AllowEdits = True
6. Else
7. Me.AllowAdditions = True
8. Me.AllowDeletions = False
9. Me.AllowEdits = False
10. End If
Two things

Define 'that record' and
Define under what circumstances you want the record to be edited.


M TB
Jul 19 '07 #6
Two things

Define 'that record' and
Define under what circumstances you want the record to be edited.


M TB
Im very new at access and I really don't know much of VBA programming. So Im just looking for an easy way to control the data entry process. Can I create a Command Button and lets say we call it (Edit) and from there you could work in edit mode for that form? A (delete) Button etc. I was thinking about running These command buttons from a Main Form Menu. I just dont know the language to make this work correctly. If you have any better suggestions I would highly appreciate it.
Jul 19 '07 #7
MikeTheBike
639 Expert 512MB
Im very new at access and I really don't know much of VBA programming. So Im just looking for an easy way to control the data entry process. Can I create a Command Button and lets say we call it (Edit) and from there you could work in edit mode for that form? A (delete) Button etc. I was thinking about running These command buttons from a Main Form Menu. I just dont know the language to make this work correctly. If you have any better suggestions I would highly appreciate it.
cmdEdit button

Expand|Select|Wrap|Line Numbers
  1. Sub cmdEdit_Click
  2. On Error GoTo Err_cmdEdit_Click
  3.  
  4.    Me.AllowEdits = True
  5.  
  6. Exit_cmdEdit_Click:
  7.     Exit Sub
  8.  
  9. Err_cmdEdit_Click:
  10.     MsgBox Err.Description
  11.     Resume Exit_cmdEdit_Click
  12.  
  13. End sub
The OnCurrent event will reset allow edits when you move to the next record.

cmdDeleteButton

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDelete_Click()
  2. On Error GoTo Err_cmdDelete_Click
  3.  
  4.     If MsgBox("Do you want to delete record?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
  5.  
  6.     RunCommand acCmdDeleteRecord
  7.  
  8. Exit_cmdDelete_Click:
  9.     Exit Sub
  10.  
  11. Err_cmdDelete_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_cmdDelete_Click
  14.  
  15. End Sub
Have you tried the button wizzard when placing buttons on a form.

There are options for deleting records etc. (although the code generated will be different form above).


MTB
Jul 20 '07 #8
Thanks for your patience and help . I used the code for editing you gave me. I created a Command button on the actual form the data entry is being done on and named it (Edit). I have used the code below to lock the form , and to be able to edit it. When the form is opened all the fields are locked(good) but when I click on the cmdEdit button the fields remain locked. I have saved and closed the form various times but records are still locked. I haven't done the (delete)button until I know that the code does work. Should I put the command (edit) button somewhere other than the data entry form for this code to work?

Thank You

Private Sub Form_Current()
If Me.NewRecord Then
Me.AllowEdits = True
Me.AllowDeletions = True
Else
Me.AllowEdits = False
Me.AllowDeletions = False
End If
End Sub

Private Sub cmdEdit_Click()
On Error GoTo Err_cmdEdit_Click

Me.AllowEdits = True

Exit_cmdEdit_Click:
Exit Sub

Err_cmdEdit_Click:
MsgBox Err.Description
Resume Exit_cmdEdit_Click
End Sub
Jul 20 '07 #9
I have also used the Code for deleting a record and I get an error " The command or action Deleterecord isn't available now.
Jul 20 '07 #10
MikeTheBike
639 Expert 512MB
I have also used the Code for deleting a record and I get an error " The command or action Deleterecord isn't available now.
To answer your last probelm fist I thonk you need this

Me.AllowDeletions = True
RunCommand acCmdDeleteRecord
Me.AllowDeletions = False

in the delete code.

for now, I do not know why the edit doesn'twork, it does for me.

I will think about it over the week end, but I am not sure about
Should I put the command (edit) button somewhere other than the data entry form for this code to work?
What data entry form and what other form?

MTB
Jul 20 '07 #11
KimC
4
This is exactly the issue that came up for me yesterday - my problem was the simpler version that MikeTheBike and puppydogbuddy offered up solutions for. And it worked! Thank you both!
Jul 20 '07 #12

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

Similar topics

1
by: Howie Goodell | last post by:
Hello -- I am trying to optimise a JDBC connection and an Oracle 9i database for reading millions of records at a time to a 1 Gig PC running Win2K or XP. Two questions: 1. Does anyone have...
0
by: HK | last post by:
Hello, I am new to access/sql-developement and have the follwing problem: What I finally want, is to present within a form the results of a query, that are probably read-only PLUS a field...
3
by: Vic | last post by:
Dear All, I have a database of laboratory records in Access 2000. There is one form which acts as an interface to input experimetal data. This form incorporates information from several tables....
0
by: Alienz | last post by:
Hey all. if anyone is REALLY bored please help moi. I am new to access stuff and am probably missing something obvious here. I have 2 tables that are linked via "number" in the relationship...
3
by: Mythran | last post by:
http://msdn2.microsoft.com/en-US/library/ms229057(VS.80).aspx * Do not assign instances of mutable types to read-only fields. I would have to disagree with this "Field Design" guidelines...to...
3
by: bballpinhead | last post by:
I am trying to figure out how to lock a record at the point it is opened in a form. The Access file is going to be stored on a Shared drive for 3-4 users to access. I need the capability to allow...
0
by: Cas | last post by:
Hi, I defined a detailsview in insertmode in the .aspx file. In the code-behind, i created 6 fields and adding them to the detailsview. Independantly of the detailsview, I use the datareader to...
8
by: paquer | last post by:
Database Users need to have Read/Write etc... permissions to the folder where the Database resides in order to create the lock file. I have read only users. I have set up the Shortcut that links...
1
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi, I'm having an issue in my C#.NET desktop application where two or more people viewing/editing the same record (from SQL Server) keep overwriting each others changes. Is there a setting in...
9
by: plaguna | last post by:
How can I change a record to Read Only? I have a Database (MS Access 2007) in a public folder, which many people have access to it and, we have no control over some of them to make unnecessary...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
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...

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.