Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using SQL instead of DAO 2

Status
Not open for further replies.

Jackvmae

Programmer
Feb 18, 2004
17
0
0
US
I recently read that it is faster to add a record to a table using SQL instead of DAO. So I would like to change my DAO code to SQL, but all the SQL syntax I've tried results in errors. Can someone provide me with SQL syntax to accomplish the same as this DAO procedure:

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblCustomers")

With rst
.AddNew
!CustomerName = Me.CusName
!CustomerTitle = Me.CusTitle
.Update
End With
 
Hi Jackvmae,

I'm not sure what your performance gain will be on a single record insert but here it is:

[blue]
Code:
DoCmd.RunSQL "INSERT INTO tblCustomers ( CustomerName, CustomerTitle) VALUES ('" & Me.CusName & "', '" & Me.CusTitle & "');"
[/blue]


Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Before you rush to change, think about error handling and think about interaction with the user.

What happens if the customer already exists
(a) in your DAO code
(b) in Tony's code
?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top