Creating a Command Button to Save and Clear Records on a form

dbeale

New member
Local time
Today, 14:55
Joined
Apr 22, 2008
Messages
4
i am new to access and learning more and more each day, but i cant figure out how to creat a command button that will save all the data that has been put in and clear all fields ready for next user to fill out. hope some one out there can help me >>>>??????:eek:
 
Simple Software Solutions

First are you using a bound form or not? If bound then data is automatically saved whe the user changes the data. To go to a blank record use the DoCmd GotoRecord acNew command on the OnClick of the Button
 
not to sure

im not sure if it is bound or not, i have attached the database i have attempted to make, could you tell me if it is bound by this ?

thank you
 

Attachments

You have a bound form - which you can tell because it has a recordsource (MainTable) in its recordsource property and each control shows the name of a field when in design view.

So, to save the record all someone has to do is navigate to a new record, or you can put this code in the click event of a button:

DoCmd.RunCommand acCmdSave

See here for how to access the code window to put that in:
http://www.btabdevelopment.com/main/QuickTutorials/Wheretoputcodeforevents/tabid/56/Default.aspx
 
It's just a little past 6am where Bob lives, and he apparently hasn't had his morning coffee yet! Actually, as Bob knows, the command should be

DoCmd.RunCommand acCmdSaveRecord

to save a record.

DoCmd.RunCommand acCmdSave

saves an object, such as a form, combobox, etc.

Linq ;0)>
 
Last edited:
still cant do it :)

thanks for the quick reply, i have done exactly what u have told me to do, and have put it in the VB bit, but how do you now connect that to a button ??

Sorry to be a pain, this is my first database i have made
 
thanks for the quick reply, i have done exactly what u have told me to do, and have put it in the VB bit, but how do you now connect that to a button ??

Sorry to be a pain, this is my first database i have made

You don't "connect it to a button." Apparently you took the screenshots I gave a little TOO literal.

1. you select the button on the form in design view.
2. You then go to the properties dialog and find the EVENTS tab.
3. Find the event listed that says CLICK.
4. click in the area next to the word CLICK and a drop down appears.
5. From that drop down select [EVENT PROCEDURE]
6. Click on the Ellipsis that appears to the right of the words [EVENT PROCEDURE]
7. That should open up the VBA window and where you see
Private Sub YourCommandButtonNameHere_Click()

End Sub

you would type in the code Linq gave in between those two lines.
8. Then save your form and you should be good to go.
 
It's just a little past 6am where Bob lives, and he apparently hasn't had his morning coffee yet!
THAT'S THE PROBLEM!!!! I don't DRINK coffee... I think I should try to resist the temptation to answer on the forums when I get up in the morning. :D
 
I had to give it up an few years ago, and it is a definite impediment to programming!

Linq :D
 
ok ok i know im bumb

i really cant do it, i put the code in where you told me too, and saved it , went to try it out on the button and it brought up the vb code bit again, and highlighted it in yellow, i have attached the database to hjopefully show you were i was going wrong ?????:confused:
 

Attachments

The problem is, in the OnClick event for Command93 (your Save button) you used the Command Button Wizard which generates the code, including Error Handling code (which is good) but in placing the DoCmd.RunCommand acCmdSave line, you apparently deleted some of the error handling code. The code that remained was trying to refer to a line that was no longer there and hence the error was thrown. So, you need to replace

Code:
Private Sub Command93_Click()

DoCmd.RunCommand acCmdSaveRecord
    Exit Sub

Err_Command93_Click:
    MsgBox Err.Description
    Resume Exit_Command93_Click
    
End Sub

with
Code:
Private Sub Command93_Click()
On Error GoTo Err_Command93_Click


    DoCmd.RunCommand acCmdSaveRecord
 
Exit_Command93_Click:
    Exit Sub

Err_Command93_Click:
    MsgBox Err.Description
    Resume Exit_Command93_Click
    
End Sub

You've also got a lot of code in there, from previous attempts, that's going to confuse you, sooner or later, and need to be gotten rid of. So:

Make a backup copy of your database.

You've only got the one command button, Command93, so for any other subs in your code module, except Command39, that have Click as part of the sub header, such as

Private Sub Whatever_Click()

need to be deleted. Start at the header and carefully hi-light down thru the End Sub line, then delete it.

You also need to delete

Code:
Private Sub Form_Current()
DoCmd.RunCommand acCmdSave
End Sub

as it accomplishes nothing here, and will, in fact, throw another error, because it's missing an argument.
 

Users who are viewing this thread

Back
Top Bottom