I am not new to VBA, but I am to stored procedures. I need to use 2 variables from a from in my SP and I'm not quite sure how to do that. I found some info and code to help me in this forum and books online, but it's not working as I expected. I think I'm close but need a nudge in the right direction. Here's my SP and VBA code:
**********
SP
**********
CREATE PROCEDURE PremTaxReport
AS
DECLARE @PTRYear varchar
DECLARE @Co varchar
INSERT INTO dbo.PremTaxReport (Type, StateCode,EffDate, TranAmt, Face)
SELECT dbo.StateAbbrev.Type, dbo.vwGLGNT.StateCode, dbo.vwGLGNT.EffDate,dbo.vwGLGNT.TranAmt,dbo.vwGLGNT.Face
FROM dbo.vwGLGNT
WHERE (DatePart(yyyy,[EffDate])) = @PTRYear and Co = @Co
GO
********************
VBA
*********************
Dim adoCnn As ADODB.Connection
Dim adoCmd As ADODB.Command
Set adoCnn = New ADODB.Connection
Set adoCmd = New ADODB.Command
With adoCnn
.ConnectionString = "Driver={SQL Server};" & _
"Server=tamlrpcdbs1;" & _
"Database=glgnt;" & _
"Trusted_Connection=Yes"
"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=password;Initial Catalog=GLGNT;Data Source=TAMLRPCDBS1"
If .State = 0 Then .Open
End With
With adoCmd
.ActiveConnection = adoCnn
.CommandText = "PremTaxReport"
.CommandType = adCmdStoredProc
.Parameters.Refresh
.Parameters(0) = Me!MyYear
.Parameters(1) = Me!Company
.Execute
End With
'**********************************************
END VBA
***********************************************
**********
SP
**********
CREATE PROCEDURE PremTaxReport
AS
DECLARE @PTRYear varchar
DECLARE @Co varchar
INSERT INTO dbo.PremTaxReport (Type, StateCode,EffDate, TranAmt, Face)
SELECT dbo.StateAbbrev.Type, dbo.vwGLGNT.StateCode, dbo.vwGLGNT.EffDate,dbo.vwGLGNT.TranAmt,dbo.vwGLGNT.Face
FROM dbo.vwGLGNT
WHERE (DatePart(yyyy,[EffDate])) = @PTRYear and Co = @Co
GO
********************
VBA
*********************
Dim adoCnn As ADODB.Connection
Dim adoCmd As ADODB.Command
Set adoCnn = New ADODB.Connection
Set adoCmd = New ADODB.Command
With adoCnn
.ConnectionString = "Driver={SQL Server};" & _
"Server=tamlrpcdbs1;" & _
"Database=glgnt;" & _
"Trusted_Connection=Yes"
"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=password;Initial Catalog=GLGNT;Data Source=TAMLRPCDBS1"
If .State = 0 Then .Open
End With
With adoCmd
.ActiveConnection = adoCnn
.CommandText = "PremTaxReport"
.CommandType = adCmdStoredProc
.Parameters.Refresh
.Parameters(0) = Me!MyYear
.Parameters(1) = Me!Company
.Execute
End With
'**********************************************
END VBA
***********************************************