Avatar of Gite
GiteFlag for Canada

asked on 

ADO Me.RecordSet invalid recordset property

I have a form which is not updatable and based on an ado recordset (see code)
Previously, the commented section was not commented, and the with cmd section wasn't there. It worked fine.
Recently, Il replaced it with the cmd section and it doesn't work any more.
On the insruction Set Me.Recordset = rst, I get  an error message "7965 The object you entered is not a valid recordset property"
What is wrong?

In the code, I have also listed the SQL Server (2008) stored procedure being used in the with cmd section. The field is NORecherche is unique.
Private Sub Form_Open(Cancel As Integer)
    Dim SQL As String
    Dim cmd As New ADODB.Command
    Dim rst As New ADODB.Recordset
    If cnUtil.State <> adStateOpen Then
        cnUtil.Open sDemelerChaine(sConnUtil)
    End If
On Error GoTo Terminer
    rst.CursorLocation = adUseClient
    rst.CursorType = adOpenKeyset
'    rst.Open SQL, cnUtil, adOpenKeyset
'    SQL = "SELECT     dbo.tbRechercheExperts.ID, dbo.tbRechercheExperts.NoRecherche, dbo.tbRechercheExperts.Initiales,dbo.tbRechercheExperts.NbBons, dbo.tbRechercheExperts.DateReponse,dbo.tbRechercheExperts.Statut, " & _
'                      " dbo.tbRechercheExperts.DateDemande, CASE WHEN FC.NoFiche IS NULL THEN H.Prénom + ' ' + H.Nom ELSE FC.PrénHomme + ' ' + FC.NomHomme END AS Homme," & _
'                      " CASE WHEN FC.NoFiche IS NULL THEN F.Prénom + ' ' + F.Nom ELSE FC.PrénFemme + ' ' + FC.NomFemme END AS Femme, CASE WHEN FC.NoFiche IS NULL" & _
'                      " THEN TypeRecherche ELSE 3 END AS Type" & _
'        " FROM         dbo.tbRechercheExperts  LEFT OUTER JOIN" & _
'                      " [ma-arbres" & sSourceBD & "].dbo.tbPersonnes AS H ON dbo.tbRechercheExperts.NoHomme = H.NoPersonne LEFT OUTER JOIN" & _
'                      " [ma-arbres" & sSourceBD & "].dbo.tbPersonnes AS F ON dbo.tbRechercheExperts.NoFemme = F.NoPersonne LEFT OUTER JOIN" & _
'                      " [mesaieux" & sSourceBD & "].dbo.tbSiteFiches AS FC ON dbo.tbRechercheExperts.NoFiche = FC.NoFiche" & _
'        " WHERE     (dbo.tbRechercheExperts.ID = '" & Me.OpenArgs & "')"
    With cmd
        .ActiveConnection = cnUtil
        .CommandType = adCmdStoredProc
        .CommandText = "spRecherchesServClientele"
        .Parameters.Append cmd.CreateParameter("@ID", adVarChar, adParamInput, 20, Me.OpenArgs)
        Set rst = .Execute
    End With
    
    
    
    Set Me.Recordset = rst
    Exit Sub
Terminer:
    Cancel = True

End Sub




USE [ma-admin-01]
GO
/****** Object:  StoredProcedure [dbo].[spRecherchesServClientele]    Script Date: 10/06/2011 12:15:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[spRecherchesServClientele] 
	-- Add the parameters for the stored procedure here
	@ID varchar(20) 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT     dbo.tbRechercheExperts.ID, dbo.tbRechercheExperts.NoRecherche, dbo.tbRechercheExperts.Initiales,dbo.tbRechercheExperts.NbBons, 
	dbo.tbRechercheExperts.DateReponse,dbo.tbRechercheExperts.Statut,
	dbo.tbRechercheExperts.DateDemande, 
	CASE WHEN tbRechercheExperts.NoFiche IS NULL THEN 
	 CASE WHEN TypeRecherche IN (0, 1) THEN H.Prénom + ' ' + H.Nom 
	 ELSE CASE E.Sexe WHEN 1 THEN E.Prénom + ' ' + E.Nom ELSE '' END
	 END
	ELSE 
	 CASE tbRechercheExperts.TypeRecherche WHEN 1 THEN FC.PrénHomme + ' ' + FC.NomHomme 
	 WHEN 2 THEN CASE B.Sexe WHEN 1 THEN B.PrénEnfant + ' ' + B.NomEnfant ELSE '' END
	 WHEN 3 THEN CASE S.Sexe WHEN 1 THEN S.PrénDéfunt + ' ' + S.NomDéfunt ELSE '' END
	 END
	END AS Homme,
	CASE WHEN tbRechercheExperts.NoFiche IS NULL THEN 
	 CASE WHEN TypeRecherche IN (0, 1) THEN F.Prénom + ' ' + F.Nom 
	 ELSE CASE E.Sexe WHEN 0 THEN E.Prénom + ' ' + E.Nom ELSE '' END
	 END
	ELSE 
	 CASE tbRechercheExperts.TypeRecherche WHEN 1 THEN FC.PrénFemme + ' ' + FC.NomFemme  
	 WHEN 2 THEN CASE B.Sexe WHEN 0 THEN B.PrénEnfant + ' ' + B.NomEnfant ELSE '' END
	 WHEN 3 THEN CASE S.Sexe WHEN 0 THEN S.PrénDéfunt + ' ' + S.NomDéfunt ELSE '' END
	 END 
	END AS Femme, 
	CASE WHEN tbRechercheExperts.NoFiche IS NULL THEN CASE WHEN TypeRecherche BETWEEN 1 AND 3 THEN  1 ELSE 0 END ELSE 2 END AS TypeRecherche,
	CASE WHEN TypeRecherche IN (0, 1) THEN  'M' WHEN TypeRecherche IN (2, 4) THEN  'B' ELSE 'S' END AS TypeActe
	FROM dbo.tbRechercheExperts  
	LEFT OUTER JOIN [ma-arbres-01].dbo.tbPersonnes AS H ON dbo.tbRechercheExperts.NoHomme = H.NoPersonne 
	LEFT OUTER JOIN [ma-arbres-01].dbo.tbPersonnes AS F ON dbo.tbRechercheExperts.NoFemme = F.NoPersonne 
	LEFT OUTER JOIN [ma-arbres-01].dbo.tbPersonnes AS E ON dbo.tbRechercheExperts.NoEnfant = E.NoPersonne 
	LEFT OUTER JOIN [mesaieux-01].dbo.tbSiteFiches AS FC ON dbo.tbRechercheExperts.NoFiche = FC.NoFiche
	LEFT OUTER JOIN [ma-bs-01].dbo.tbSiteBaptemes AS B ON dbo.tbRechercheExperts.NoFiche = B.NoActe
	LEFT OUTER JOIN [ma-bs-01].dbo.tbSiteSepultures AS S ON dbo.tbRechercheExperts.NoFiche = S.NoActe
	WHERE     (dbo.tbRechercheExperts.ID = @ID)END

Open in new window

Microsoft DevelopmentMicrosoft AccessMicrosoft SQL Server

Avatar of undefined
Last Comment
Gite
Avatar of Preece
Preece
Flag of United States of America image

I think the problem might be that you are using a single quote as a comment marker.  This works in VB and VB.NET, but not sql.  Use this instead:

/*
commented code
goes here
*/


Preece
Avatar of Preece
Preece
Flag of United States of America image

Or you can use two dashes for a single line comment:

-- single line comment in sql
Avatar of Gite
Gite
Flag of Canada image

ASKER

I executed the stocked procedure as is in SQL Server and it worked fine. The execute instruction works fine.
The problem is with the set Me.recordset statement
Avatar of Preece
Preece
Flag of United States of America image

My bad.  Your example has a mix of sql and a vb function.  Still looking...

Preece
ASKER CERTIFIED SOLUTION
Avatar of Leigh Purvis
Leigh Purvis
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Gite
Gite
Flag of Canada image

ASKER

Great. The problem was with the .execute!
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo