Question : How to use stored procedure for access data project

I'm trying to open a stored procedure and assign a value to a label on a page in Access data project.  below is the code.  When I run the page I get the following msg:
"run-time error 91: Object variable or With block variable not set "
The stored procedure runs when in sql server management studio

Please assist.  Thanks.

Private Sub Form_Current()
On Error GoTo ProcError
Dim rst As Recordset
Dim cmd As ADODB.Command
Dim strStoredProcedure As String
Dim prmPersonID As ADODB.Parameter
Dim varPersonID As Variant
Dim valPersonID As Variant
Dim prmReturn As Variant

valPersonID = Nz(Me.PersonID, 0)

strStoredProcedure = "stp_APDB_PersonStatusByPersonID"
Set cmd = New ADODB.Command
With cmd
Set prmPersonID = .CreateParameter("varPersonID", adInteger, adParamInput, , valPersonID)

.Parameters.Append prmPersonID

    .ActiveConnection = CurrentProject.Connection
    .CommandText = strStoredProcedure
    .CommandType = adCmdStoredProc
    .Execute

    Me.lblStatus.Caption = rst.Status
    'cleanup the ADO objects
Set prmPersonID = Nothing

Set rst = Nothing
Set cmd = Nothing

End With
end Sub
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
below is the stored procedure

ALTER PROCEDURE [dbo].[stp_APDB_PersonStatusByPersonID]
	-- Add the parameters for the stored procedure here	
@PersonID int

AS
declare 	@sql    nvarchar(max)  
declare     @params nvarchar(max)
declare		@Status nvarchar(12)

set @sql = ''
set @params = ''
set @sql = N'select [Status] from vw_PersonUnit where PersonID = @PersonID'

set @params = N'@PersonID int'
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	EXEC @Status = sp_executesql @sql,@params,
@PersonID = @PersonID;
print @sql

return @Status
END

Answer : How to use stored procedure for access data project

I figured it out.  I needed to add the cmd in the rst.open line.  It should read, rst.open cmd
Random Solutions  
 
programming4us programming4us