G
Guest
This below is my code that have written, but I keep getting an error message
on the line highlighted with stars.
The error is - 3704 - Operation is not allowed when the object is closed.
what does this mean?
Private Sub cmdImport_Click()
Dim Conn As ADODB.Connection
Dim RS As ADODB.Recordset
Dim Comm As ADODB.Command
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim strConn As String
Dim strInsert As String
Dim strSelect As String
strConn = "Provider=sqloledb;Data Source=SLIDER\BISR;Initial" & _
"Catalog=NameofSQLServer;User Id=myunsername;Password=mypassword"
strSelect = "SELECT * FROM dbo.servicing_jobs"
********Set objRS = objConn.Execute(strSelect)*******
Set Conn = New ADODB.Connection
Set RS = New ADODB.Recordset
Set Comm = New ADODB.Command
Conn.Open strConn
Comm.ActiveConnection = Conn
Comm.CommandType = adCmdText
Do While Not objRS.EOF
strInsert = "INSERT INTO tblServicing"
Comm.CommandText = strInsert
Comm.Execute
objRS.MoveNext
Loop
UpdateAwardErr:
If Err.Number <> 0 Then
MsgBox Err.Number & Err.Description
Exit Sub
Else
MsgBox "Records were successfully inserted", vbInformation, "ServicingJobs
Update"
Exit Sub
End If
End Sub
on the line highlighted with stars.
The error is - 3704 - Operation is not allowed when the object is closed.
what does this mean?
Private Sub cmdImport_Click()
Dim Conn As ADODB.Connection
Dim RS As ADODB.Recordset
Dim Comm As ADODB.Command
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim strConn As String
Dim strInsert As String
Dim strSelect As String
strConn = "Provider=sqloledb;Data Source=SLIDER\BISR;Initial" & _
"Catalog=NameofSQLServer;User Id=myunsername;Password=mypassword"
strSelect = "SELECT * FROM dbo.servicing_jobs"
********Set objRS = objConn.Execute(strSelect)*******
Set Conn = New ADODB.Connection
Set RS = New ADODB.Recordset
Set Comm = New ADODB.Command
Conn.Open strConn
Comm.ActiveConnection = Conn
Comm.CommandType = adCmdText
Do While Not objRS.EOF
strInsert = "INSERT INTO tblServicing"
Comm.CommandText = strInsert
Comm.Execute
objRS.MoveNext
Loop
UpdateAwardErr:
If Err.Number <> 0 Then
MsgBox Err.Number & Err.Description
Exit Sub
Else
MsgBox "Records were successfully inserted", vbInformation, "ServicingJobs
Update"
Exit Sub
End If
End Sub