Hi,
I've used the following code I found in a book to run sql select queries. This works fine. However, I'd aslo like to do update and insert statements, which this code won't do. I've tried adjusting it in a number of ways, but, so far, unsuccesfully. If anyone could tell me how to adjust these two functions so I could do update and insert queries I would be very much obliged.
tnx!
(I'm using access 2010)
Sub OpenConnection()
If Not connected Then
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.Open CurrentProject.Connection
cnn.Close
Set cnn = Nothing
connected = True
End If
End Sub
Function ExecCommand(dbSQLstring As String) As ADODB.Recordset
Call OpenConnection
Dim rec_set As ADODB.Recordset
Set rec_set = New ADODB.Recordset
Dim cmnd As ADODB.Command
Set cmnd = New ADODB.Command
cmnd.ActiveConnection = CurrentProject.Connection
cmnd.CommandText = dbSQLstring
Set rec_set = cmnd.Execute
Set ExecCommand = rec_set
End Function
I've used the following code I found in a book to run sql select queries. This works fine. However, I'd aslo like to do update and insert statements, which this code won't do. I've tried adjusting it in a number of ways, but, so far, unsuccesfully. If anyone could tell me how to adjust these two functions so I could do update and insert queries I would be very much obliged.
tnx!
(I'm using access 2010)
Sub OpenConnection()
If Not connected Then
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.Open CurrentProject.Connection
cnn.Close
Set cnn = Nothing
connected = True
End If
End Sub
Function ExecCommand(dbSQLstring As String) As ADODB.Recordset
Call OpenConnection
Dim rec_set As ADODB.Recordset
Set rec_set = New ADODB.Recordset
Dim cmnd As ADODB.Command
Set cmnd = New ADODB.Command
cmnd.ActiveConnection = CurrentProject.Connection
cmnd.CommandText = dbSQLstring
Set rec_set = cmnd.Execute
Set ExecCommand = rec_set
End Function