This line produces error 3709: The connection cannot be used to perform this operation. It is either closed or invalid in this context. I suspect it has to do with the strQ variable that stores the name of a query. however, the name produced from the debug window is a valid query object. The query object is a selection based on another query and uses distinct rows. Not sure if this matters.
I'm not very versed in ADO and kinda lost. Anyone see what I'm doing wrong? Thanks for any responses.
"rstTL.Open strQ, cnn1, adCmdTable, adLockReadOnly"
Code
-----------------------------------------------------
Private Sub btnDefects_Click()
Dim rstDIS As ADODB.Recordset
Dim rstTL As ADODB.Recordset
Dim cnn1 As ADODB.Connection
Dim strQ As String
Dim strTL As String
Dim strPath As String
strPath = "C:\Terry\Defects\Defects.mdb"
Set cnn1 = New ADODB.Connection
With cnn1
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source").Value = strPath
'.Open
End With
' Define Selection.
strQ = "qry_SEL_DCEXP_N"
Set rstTL = New ADODB.Recordset
Set rstDIS = New ADODB.Recordset
rstTL.Open strQ, cnn1, adCmdTable, adLockReadOnly
rstDIS.Open "tblDiscrepancies", cnn1, adCmdTable, adLockBatchOptimistic
'write records to Discrepancies table
Do While Not rstTL.EOF
'set variable for team_lead
strTL = rstTL!Team_Lead
rstDIS.AddNew
rstDIS!DefectNumber = DMax("DefectNumber", "tblDiscrepancies") + 1
rstDIS!Originator = Me.cmbOrig
rstDIS!Admin = Me.cmbAdmin
rstDIS!Owner = strTL
rstDIS!SubmitDate = Now()
rstDIS!ActionType = "Defect"
rstDIS!Analysis = "Current Express Phase Missing from these open projects."
rstDIS!Request = "TL to update RTM."
rstDIS.Update
'Write records to Discrepancy Detail
'Write Records to CR Detail
rstTL.MoveNext
Loop
Set rstTL = Nothing
Set rstDIS = Nothing
rstTL.Close
rstDIS.Close
I'm not very versed in ADO and kinda lost. Anyone see what I'm doing wrong? Thanks for any responses.
"rstTL.Open strQ, cnn1, adCmdTable, adLockReadOnly"
Code
-----------------------------------------------------
Private Sub btnDefects_Click()
Dim rstDIS As ADODB.Recordset
Dim rstTL As ADODB.Recordset
Dim cnn1 As ADODB.Connection
Dim strQ As String
Dim strTL As String
Dim strPath As String
strPath = "C:\Terry\Defects\Defects.mdb"
Set cnn1 = New ADODB.Connection
With cnn1
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source").Value = strPath
'.Open
End With
' Define Selection.
strQ = "qry_SEL_DCEXP_N"
Set rstTL = New ADODB.Recordset
Set rstDIS = New ADODB.Recordset
rstTL.Open strQ, cnn1, adCmdTable, adLockReadOnly
rstDIS.Open "tblDiscrepancies", cnn1, adCmdTable, adLockBatchOptimistic
'write records to Discrepancies table
Do While Not rstTL.EOF
'set variable for team_lead
strTL = rstTL!Team_Lead
rstDIS.AddNew
rstDIS!DefectNumber = DMax("DefectNumber", "tblDiscrepancies") + 1
rstDIS!Originator = Me.cmbOrig
rstDIS!Admin = Me.cmbAdmin
rstDIS!Owner = strTL
rstDIS!SubmitDate = Now()
rstDIS!ActionType = "Defect"
rstDIS!Analysis = "Current Express Phase Missing from these open projects."
rstDIS!Request = "TL to update RTM."
rstDIS.Update
'Write records to Discrepancy Detail
'Write Records to CR Detail
rstTL.MoveNext
Loop
Set rstTL = Nothing
Set rstDIS = Nothing
rstTL.Close
rstDIS.Close