Thread: Queries
View Single Post
  #5 (permalink)  
Old September 8th, 2003, 09:27 AM
Bob Bedell Bob Bedell is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Lastly, if you are using a SQL INSERT statement to add a record instead of the recordset's AddNew method, you don't need a recordset object at all. You only need a connection on which to execute the SQL command:

Private Sub Command0_Click()
  Dim cnn As ADODB.Connection
  Dim strProvider As String
  Dim strDataSource As String

  Set cnn = New ADODB.Connection

  strProvider = "Microsoft.Jet.OLEDB.4.0"
  strDataSource = CurrentProject.Path & "\MyDatabase.mdb"

  cnn.Open "Provider = " & strProvider & "; Data Source = " & strDataSource

  cnn.Execute "INSERT INTO tblCustomers SELECT * FROM tblCustomers2 " & _
                   "WHERE [LastName] = '" & txtLastName & "'"

End Sub

Reply With Quote