troubleshooting Question

How to use stored procedure for access data project

Avatar of jvantassel1
jvantassel1Flag for United States of America asked on
Microsoft Access
9 Comments1 Solution773 ViewsLast Modified:
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

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

Set rst = Nothing
Set cmd = Nothing

End With
end Sub
below is the stored procedure

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

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'
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.

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

return @Status

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros