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 >>>>??????
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
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:
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.
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 ?????
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.