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

How Do I create a Button that unlocks a form for editing?

Hi,

I am new to access and I am trying to find my way around, I have created a form but I do not want any editing to occur unless I click on an Edit button. But I still want to navigate the forms to see which record needs editing can someone help?

Sam
Sep 8 '10 #1
3 16267
TheSmileyCoder
2,322 Expert Mod 2GB
You start by adding a button to your form, and name it btn_Edit and give it caption "Edit",and under Events look for OnClick and then click the 3 ... on the right hand side. Select Event Procedure, and you will now enter the VBA (Visual Basic for Applications window). Here you can write the code. When you start it will look something like:

Expand|Select|Wrap|Line Numbers
  1. Private sub btn_Edit_OnClick()
  2.  
  3. End Sub
Between the 2 lines you now add:
Expand|Select|Wrap|Line Numbers
  1. Private sub btn_Edit_OnClick()
  2.   Me.AllowEdits=True
  3. End Sub
the Me. is a reference to the form itself.

Now you need one more thing and that is to disallow edits whenever the user moves to the next record, which can be done be selecting your form (click small box in upper left corner of form and go to events again. Here you click Current and again click the ... and select Event Procedure.
It will go to VBA window looking like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.    Me.AllowEdits=False
  3. End Sub
Thats the basic functionality, and you can then choose to make it more advanced from here, by for instance changing the button caption when it is pressed. When you click it:
Expand|Select|Wrap|Line Numbers
  1. Private sub btn_Edit_OnClick()
  2.   Me.AllowEdits=True
  3.   Me.btn_Edit.Caption="Editing"
  4. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.    Me.AllowEdits=False
  3.    Me.btn_Edit.Caption="Edit"
  4. End Sub
Sep 8 '10 #2
this has worked wonders and I cannot thank you enough for your quick help. But I have one more question? Can this also work on trying to create a new record. what I did was play with it and I screwed up my Autonumber which I am going and reset using the crude methods of Access. is is possible to also make sure no new records are created unless I press this button?
Sep 8 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
You should in the future make a new thread for a new question, but maybe some nice Moderator will split it :P

Anyways:
Adding a button, btn_New, caption "New", click the Events, and the OnClick button to get the code window and write:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_New_Click()
  2.     Me.AllowAdditions = True
  3.     DoCmd.GoToRecord , , acNewRec
  4. End Sub
This will allow user to go to a new record, but we also want to prevent him from navigating by mousewheel to a new record (maybe you don't care, depends on your application)
So in our Form_Current() we add:
Expand|Select|Wrap|Line Numbers
  1.   Me.AllowAdditions=Me.NewRecord
This will turn off additions unless we are looking at a new record. Access can be a bit funny though, if you have a form with no records yet, and AllowAdditions=False, because then it will hide the entire form (including the buttons...) so to prevent this case from happening, we do:
Select Form->events->OnLoad and write:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   Me.AllowAdditions=True
  3. End Sub
Sep 8 '10 #4

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

Similar topics

2
by: Terry | last post by:
I have cerated a Form, ExamsFrm, which is used to input details of exams taken at several Centres. It dosplays details from StudentTbl and has a SubForm which displays details from ExamsTble. I...
0
by: Qajussi | last post by:
Hi! I am trying to create data entry forms like MS access forms using asp.net. I am talking about a form like MS access forms which let you enter a new record, edit, navigate to previous and next...
1
by: regelcom | last post by:
My son is trying to create an about form button for a form he has already created. Any help would be great. Thanks
6
by: stellstarin | last post by:
I have a HTML page containing two submit buttons in the same form.When the form is submitted,I want to know through which submit button the form was submitted. Is there any event or property which...
1
by: Neeraj | last post by:
hi I want to make clone of current Form which is currently seen.I Used attribute above the class declaration which extends Form. Impleament the ICloneable interface and Make method which code is...
9
by: sabra | last post by:
What I am trying to do is to create a special form to enter post dated checks. For example if a costumer is paying me in payments by credit card etc. for every first of the month for the upcoming 24...
1
by: Chandrajit | last post by:
Hi, Please help I what show some message when user click on X button of form which is at upper side corner of the form in vb.net
6
by: anurathna1971 | last post by:
1.create a registration form in vb in which first name,last name,username,password and confirm password fields should not be left blank and email address should contain@symbol. 2.design a form...
2
by: buddyr | last post by:
Hello, I have a cmd button on form to search for serial number. I notice when I search for record-that if I don't start at the beginning of records I might not find the record. example: if I am...
6
by: mercout | last post by:
Hey, I've been trying to create a search form in access for a while now, searching through books and emails. I have the search form set up with 11 combo box's, 3 text box's, a view button, and a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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...

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.