PC Review


Reply
Thread Tools Rate Thread

Cannot change the ActiveConnection property of a recordset object....

 
 
m.p.fletcher@googlemail.com
Guest
Posts: n/a
 
      9th Dec 2006
....which has a command object as its source.

Is the error mesage that is currently driving me nutty. Let me explain.
The function causing the problem is as follows:

Public Type SPDataset
Name As String 'Name of the stored procedure
arrParameters() As String
Source As String 'The calling Form
bSuccess As Boolean 'If everything went ok
End Type

Public Function sqlSP(ExecuteSP As SPDataset) As ADODB.Recordset

Dim sqlConn As ADODB.Connection
Dim sqlCmd As ADODB.Command
Dim sqlRS As ADODB.Recordset
Dim N As Integer

' Establish connection.
Set sqlRS = New ADODB.Recordset
Set sqlCmd = New ADODB.Command
Set sqlConn = New ADODB.Connection

'Make sure the project is connected to the server
If (CurrentProject.IsConnected = False) Then
'Stop the form from loading
MsgBox "You must be logged in to perform this action. Please
login and try again.", vbExclamation, "Database Error"
ExecuteSP.bSuccess = False

Else

sqlConn.ConnectionString = CurrentProject.Connection
sqlConn.Open

sqlConn.CursorLocation = adUseClient 'Cache data locally

' Open recordset.
With sqlCmd
.ActiveConnection = sqlConn
.CommandText = ExecuteSP.Name
.CommandType = adCmdStoredProc
.Parameters.Refresh
'Load the parameters
If IsArrayAllocated(ExecuteSP.arrParameters) Then
For N = LBound(ExecuteSP.arrParameters) To
UBound(ExecuteSP.arrParameters)
.Parameters("@" & ExecuteSP.arrParameters(N,
0)).Value = ExecuteSP.arrParameters(N, 1)
Next N
End If
Set sqlRS = .Execute()
End With

'Set the output parameters if they are requested
If IsArrayAllocated(ExecuteSP.arrParameters) Then
For N = LBound(ExecuteSP.arrParameters) To
UBound(ExecuteSP.arrParameters)
If Not ExecuteSP.arrParameters(N, 2) = "" Then
If ExecuteSP.arrParameters(N, 2) = True Then
ExecuteSP.arrParameters(N, 1) =
sqlCmd.Parameters("@" & ExecuteSP.arrParameters(N, 0))
End If
End If
Next N
End If

Set sqlRS.ActiveConnection = Nothing
sqlConn.Close
Set sqlConn = Nothing

Set sqlSP = sqlRS

Set sqlRS = Nothing
Set sqlCmd = Nothing
ExecuteSP.bSuccess = True

End If

End Function

The idea behind it was that I would simply pass this function the
required parameters and it would pass back a disconnected recordset. It
works 90% of the time, with and without passed parameters but sometimes
I get the aforementioned error message. I am not doing anything
differently so why is the function behavining so awkwardly?

Kind regards,
Marc

 
Reply With Quote
 
 
 
 
m.p.fletcher@googlemail.com
Guest
Posts: n/a
 
      9th Dec 2006
I believe the error message is occuring when there is more than one SP
parameter, since all SP's taking a single parameter run just find (i.e.
the 90% of the time I refered to in my previous post).

(E-Mail Removed) wrote:

> ...which has a command object as its source.
>
> Is the error mesage that is currently driving me nutty. Let me explain.
> The function causing the problem is as follows:
>
> Public Type SPDataset
> Name As String 'Name of the stored procedure
> arrParameters() As String
> Source As String 'The calling Form
> bSuccess As Boolean 'If everything went ok
> End Type
>
> Public Function sqlSP(ExecuteSP As SPDataset) As ADODB.Recordset
>
> Dim sqlConn As ADODB.Connection
> Dim sqlCmd As ADODB.Command
> Dim sqlRS As ADODB.Recordset
> Dim N As Integer
>
> ' Establish connection.
> Set sqlRS = New ADODB.Recordset
> Set sqlCmd = New ADODB.Command
> Set sqlConn = New ADODB.Connection
>
> 'Make sure the project is connected to the server
> If (CurrentProject.IsConnected = False) Then
> 'Stop the form from loading
> MsgBox "You must be logged in to perform this action. Please
> login and try again.", vbExclamation, "Database Error"
> ExecuteSP.bSuccess = False
>
> Else
>
> sqlConn.ConnectionString = CurrentProject.Connection
> sqlConn.Open
>
> sqlConn.CursorLocation = adUseClient 'Cache data locally
>
> ' Open recordset.
> With sqlCmd
> .ActiveConnection = sqlConn
> .CommandText = ExecuteSP.Name
> .CommandType = adCmdStoredProc
> .Parameters.Refresh
> 'Load the parameters
> If IsArrayAllocated(ExecuteSP.arrParameters) Then
> For N = LBound(ExecuteSP.arrParameters) To
> UBound(ExecuteSP.arrParameters)
> .Parameters("@" & ExecuteSP.arrParameters(N,
> 0)).Value = ExecuteSP.arrParameters(N, 1)
> Next N
> End If
> Set sqlRS = .Execute()
> End With
>
> 'Set the output parameters if they are requested
> If IsArrayAllocated(ExecuteSP.arrParameters) Then
> For N = LBound(ExecuteSP.arrParameters) To
> UBound(ExecuteSP.arrParameters)
> If Not ExecuteSP.arrParameters(N, 2) = "" Then
> If ExecuteSP.arrParameters(N, 2) = True Then
> ExecuteSP.arrParameters(N, 1) =
> sqlCmd.Parameters("@" & ExecuteSP.arrParameters(N, 0))
> End If
> End If
> Next N
> End If
>
> Set sqlRS.ActiveConnection = Nothing
> sqlConn.Close
> Set sqlConn = Nothing
>
> Set sqlSP = sqlRS
>
> Set sqlRS = Nothing
> Set sqlCmd = Nothing
> ExecuteSP.bSuccess = True
>
> End If
>
> End Function
>
> The idea behind it was that I would simply pass this function the
> required parameters and it would pass back a disconnected recordset. It
> works 90% of the time, with and without passed parameters but sometimes
> I get the aforementioned error message. I am not doing anything
> differently so why is the function behavining so awkwardly?
>
> Kind regards,
> Marc


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA object property change not recognized caten Microsoft Powerpoint 2 6th Oct 2009 06:40 PM
cmd.ActiveConnection property =?Utf-8?B?c21rMjM=?= Microsoft Access VBA Modules 1 11th Feb 2006 03:09 PM
how to use object variable to change the property of a Fendic Microsoft Excel Programming 4 6th Aug 2005 07:12 PM
Access 2002: bind adodb recordset to listbox recordset property Craig Buchanan Microsoft Access Form Coding 2 1st May 2005 12:14 AM
How to change the display name of a object's property in PropertyGrid X.W. Microsoft C# .NET 2 28th Feb 2005 07:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:52 PM.