PDA

View Full Version : Save command Access VBA



labonte373
08-02-2007, 01:50 PM
I am trying to code a save command to save information from a form in Access to a table in Access or even a report. Not sure how to do this.

Here is what I have so far:

Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click


Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click

End Sub

I know more needs to go in but not sure what? Any help would be great.

geekgirlau
08-02-2007, 07:55 PM
Welcome to the Board!

Is the form bound to a table or query? If so, you don't have to save it - as soon as you move to the next record or close the form, the data is saved.

If you want to create a save button for some other reason, use the Command Button Wizard on the form - Access will create the code for you. Make sure the Toolbox is displayed, and the "Control Wizards" button is selected (looks like a magic wand). Click on the "Command Button" and click somewhere on the form. You can then step through the wizard, selecting Record Operations | Save Record.

labonte373
08-06-2007, 08:13 AM
The form is not bound to a table or query. I've tried using a command button but it never saved anything or maybe I do not know where it is saving the information.

mattj
08-06-2007, 08:16 AM
The easiest method is to bind the form to a table. Set the RecordSource property of the form to the table you wish to save the data in. Create the controls on the form, and set their ControlSource property to the field in the table they should be saved in.
This way, data will be saved automatically as you enter it (technically, it will be saved as soon as the control loses focus)

HTH
Matt

labonte373
08-06-2007, 08:54 AM
So, in other words redo the form?

mattj
08-06-2007, 08:56 AM
Might as well. Use the Form's wizard. When it's done, go through the form and control properties to see what it did. It will pretty much do what I described.

Almeister9
05-02-2008, 07:20 PM
I would like to introduce you to my besterest friend,
The SQL statement INSERT INTO

e.g.

DoCmd.RunSQL " INSERT INTO tblRA " _
& "(ProdSerial, SupplierID, CustomerID, EnteredDate) VALUES('" _
& Me.ProductSerialNo & "', '" & Me.SupplierID & "', '" & Me.InvCustomerID & "', Date());"

I have this in the 'on Click' Event of a command button called "SAVE"

tblRA = the name of the table to insert data into
first set of ()'s = names of fields in table you want to insert data into
VALUES = data you want to insert in the same order as first set of ()'s

above code is for an unbound form. I use an unbound form because I can have a cancel button without creatig an empty or half filled record in the table if user changes their mind.

hope this helps.