Sample code for Button Click event

gaju_3112

Registered User.
Local time
Today, 21:30
Joined
Nov 4, 2007
Messages
38
I am new to the Access. I want the procedure to do following thing to make my concept understanding clear_
Adding Button and textbox on form, On button click, text in textbox should be stored in table named Master (Name (Text)) in database?

Please provide me step by step procedure to do this task. Though this is very simple and basic qustion but I can not proceed further without understanding this.
 
Do you have a table created already with a text field in it named 'Name'?
 
ya! you are right.
 
Start by using the Form Wizard to create your form, selecting the table name Master and choosing the field name 'Name' to appear on the form.
The next step: While in design mode select the command button and place it where you want your button to appear on the form. Click/hold and drag right and down to create a small oblong button. The command Button Wizard should come up with options.
You will be creating a button to save your record; select Record Operations and Save Record; then next> Choose Text then next>give the button a meaningful name like SaveRecordButton and click Finish
Save your form and switch to Form View
Type in a name and press the Save Record Button
then repeat the process.
 
It is always better to base a report/form on a query rather than directly on a table. This will give you more flexibility in making changes later on and also make it easier to set criteria for the data you display.
 
Important!!

And, for heaven's sake, change the field name from NAME to something else because NAME is an Access reserved word and you will only cause yourself great grief if you leave it as is.

Do not name fields, or objects, Access reserved words.
 
Adding on to this question....

So is it possible to have a form that only updates the table it is bound to after a command button is clicked? So I enter a bunch of data into a form and hit an "update button" and that data is entered into the form. But if enter all that data into the form and hit "exit button", then that record isn't created.

Can someone help me with that? Thanks.
 
So is it possible to have a form that only updates the table it is bound to after a command button is clicked? So I enter a bunch of data into a form and hit an "update button" and that data is entered into the form. But if enter all that data into the form and hit "exit button", then that record isn't created.

Can someone help me with that? Thanks.
See if this link helps.
 
Thanks for the link. My problem is that I am a complete newbie to Access and I have no idea what to do with all that code. I was hoping that there was just a way to add a line of code so that it only adds the fields to the table after hitting the control button. I am guessing that it isn't that easy?
 
Access wants to save any updated bound fields unless you take extra steps. The trick is to catch things in the BeforeUpdate event of the form and if the user has not pressed your magic button that resets the save flag then you just do a Me.Undo and clear everything. At least it gives you an opportunity to ask the user if they want to save or not. Look ghudsons code over again for just those two concepts I just gave. I think you will find it is easier than you think to impliment.
 

Users who are viewing this thread

Back
Top Bottom