submit form button

G

Guest

Hello, i have a form that takes user input in various text boxes that are not
tied to rowsources because the inserts need to be dynamic. There is a
checkbock that determines how the record(s) will be inserted. (unchecked
causes simple insert, checked performs 2 table insert) How can i perform an
insert with a command button. How can i perform the 2 inserts (into different
tables) pulling the autonumer from the first insert to populate a foreign key
during the second insert? Thank you.
 
M

Michel Walsh

Hi,

Add a VBA line like:


DoCmd.RunSQL "INSERT INTO tableName( listOfFields) VALUES( listOfValue) "


should insert a single row in the mentionned table (all the required fields
must have a values, except if they are autonumber or with a default value).

Example:


DoCmd.RunSQL "INSERT INTO table1(firstName, LastName) VALUES(
FORMS!yourFormName!FirstName, FORMS!yourFormName!LastName) "



where FirstName is and a field in table1, and a control on the mentionned
form.



Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top