Full Version: INSERT form
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
ChristopherA
I have been looking over the net and i cant seem to find anyone who has entered data with just an insert statement. Can anyone help me with some code for it, just 2 textfields which insert thier data into 2 different tables when a button is clicked. Can anybody please help?
HelloAgain
Well I will tell you how to do it with one text field, and for two you would just do it twice. Take for example a table:

CODE
TblEmployees

ID            First         Last

1              Frank       Oz
2              June        Jones
3              Bob          Smith


You form has two unbound text boxes named "FirstNameBox" and "LastNameBox", and a button named "AddNameButton"

In the AddNameButton's OnClick event, add the following code:

CODE
DIM strSQL as String

strSQL = "INSERT INTO TblEmployees (Name) VALUES ('" & me.FirstNameBox & ", '" & me.LastNameBox & "')"

CurrentDB.Execute strSQL


If you entered 'Jim' into FirstNameBox, 'Jenkins' into LastNameBox, and clicked the button, the result would be:

CODE
ID            First         Last

1              Frank       Oz
2              June        Jones
3              Bob          Smith
4              Jim           Jenkins
R. Hicks
If this is for an existing record ... use an Update Query ...
If this is for a new record ... use an Append Query ...

RDH
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.