Using VBA to add new record

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Hello,

Is there a way to use VBA to add a new record and fill in one field without
using DBO or ADO?


Thankyou
 
Assuming the field to insert is text and is taken from a field on a form

DoCmd.RunSQL "INSERT INTO TableName (FieldName) VALUES ('" & FieldOnFormName
& "')"

Hard Coded example

DoCmd.RunSQL "INSERT INTO Clients (FirstName) VALUES ('Eric')"
 
You can run an INSERT INTO SQL statement. Best way is using the Execute
method of the DAO Database object.

What's your objection to using DAO or ADO though?
 
I'm probably wrong but using DAO or ADO seem's a bit complicated, specifying
filenames or making connections to a table which is in the same access file
just seems a bit tedious just to add one field to a new record. I thought
there should be a way I could do that in 1 command.


Cheers for your response people! I will put it into action tomorrow.
 

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

Back
Top