P
Pete Davis
I have the following code that I call shortly after calling a ADO
Connection.Execute.
Public Function GetMaxID(TableName As String, FieldName As String) As
Integer
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Set conn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "Select Max(" + FieldName + ") from " + TableName
GetMaxID = CInt(rst.Fields(0))
rst.Close
End Function
The Connection.Execute works fine. I never close the connection, but I call
this function immediately after the connection.execute (which happens in
another function), and it fails on the Recordset.Open saying: "The
connection cannot be used to perform this operation. It is either closed or
invalid in this context."
Any ideas?
Pete
Connection.Execute.
Public Function GetMaxID(TableName As String, FieldName As String) As
Integer
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Set conn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "Select Max(" + FieldName + ") from " + TableName
GetMaxID = CInt(rst.Fields(0))
rst.Close
End Function
The Connection.Execute works fine. I never close the connection, but I call
this function immediately after the connection.execute (which happens in
another function), and it fails on the Recordset.Open saying: "The
connection cannot be used to perform this operation. It is either closed or
invalid in this context."
Any ideas?
Pete