Adding record through a text boxes enter event

I am new to Access and was trying to find the code to add to a text box's enter event to add a record after the uses hits enter, using the contents of the all the text boxes on the form for the record.  Can somebody give me some beginner VB code for this?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


The easiest way to insert a record is of course by using a bound form and letting Access do the work for you.

Via code:

Dim strSQL as string
strSQL = "INSERT INTO YourTable (F1, f2,f3 ...) VALUES (" & txtText1 & "," & cboCombo1 & "," & txtText2 & ")"
currentdb.execute strSQL, dbFailOnError

f1, f2, etc represent all of the fields that your form has controls for.
You would have to expand this for ALL your controls, and use delimiters appropriate for the datatypes of each field. Text needs to be enclosed in quotes; dates need to be enclosed in #'s.

(so it can get a bit complicated).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
<enter event>
<add to a text box's enter event to add a record after the uses hits enter,>

The event you are describing would actually be the textbox's after update event.

I'd recommend using a command button's click event to insert a record instead.
Hi sciarref,

If your text box is bound to table or query field, just place Dirty = False into its After Update event.
See snippet below for an example

Private Sub Field1_AfterUpdate()
Dirty = False
End Sub

Open in new window

sciarrefAuthor Commented:
Thanks works great.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.