views:

150

answers:

1

I am planning to insert value in a vba access form text box values to the table in same access file

Here i will write a insert query on the submit button click event

Is there any shortcut methods to add the value into the table?

Like seting the datasource for the textbox and inserting values of all textbox in the form using a click of button

without insert queries ????

which is better?

A: 

Not sure exacly what it is that you are asking.

To add rows to a table in VBA code you can use a DAO Recordset like this:

Dim rs As DAO.Recordset
Set rs= CurrentDb.OpenRecordset("TableName", dbOpenDynaset)

rs.AddNew
rs![ColumnName1] ="Some Value"
rs![ColumnName2] ="Some Value"
rs.Update
rs.Close

Or to run an Append Query in VBA build the SQL Statement in to a string and execute the statement like this:

CurrentDb.Execute strSQLText, dbFailOnError
Mark3308
FWIW I use currentdb instead of dimming and setting a db variable.
Tony Toews
The last code example won't work anyway, since the db variable has not been instantiated. I don't use CurrentDB much, myself, as I have my dbLocal() function that automatically caches and returns a variable instantiated with CurrentDB.
David-W-Fenton
OK amended the answer to use CurrentDb
Mark3308