Hi All
further to https://www.access-programmers.co.uk/forums/showthread.php?t=294892
I am have now converted the queries to stored procedures (in the back-end SQL server) as follows.
I have a SYSTEM DSN connection using the 'ODBC Driver 13 for SQL Server'
But they are not firing for some reason?
P.S. It seems that the ID_Subject is not being parsed through to the SP. How do I check that?
Quick summary of what should happen.
On my form, the user creates generic comments for student report results.
When they click an 'update' button, the relevant text in the comment field should be updated as per the SP.
NOTE : The comment field is RTF so i have had to consider that some text might have html tags.
The code under the button . . .
SP_Calls Module . . .
SP's created on the server
further to https://www.access-programmers.co.uk/forums/showthread.php?t=294892
I am have now converted the queries to stored procedures (in the back-end SQL server) as follows.
I have a SYSTEM DSN connection using the 'ODBC Driver 13 for SQL Server'
But they are not firing for some reason?
P.S. It seems that the ID_Subject is not being parsed through to the SP. How do I check that?
Quick summary of what should happen.
On my form, the user creates generic comments for student report results.
When they click an 'update' button, the relevant text in the comment field should be updated as per the SP.
NOTE : The comment field is RTF so i have had to consider that some text might have html tags.
The code under the button . . .
Code:
Private Sub Btn_Update_Comments_Click()
' These are calls to a MODULE - see below
Call Stp_Sname(Me.Get_Subject)
Me.Refresh
Call Stp_Fname(Me.Subj_ID)
Me.Refresh
Call Stp_HIS_001(Me.Get_Subject)
Me.Refresh
Call Stp_Him_001(Me.Subj_ID)
Me.Refresh
END SUB
SP_Calls Module . . .
Code:
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Dim IdValueToProcess As Integer
IdValueToProcess = MySubjID
Set qdf = CurrentDb.CreateQueryDef("")
qdf.ReturnsRecords = True
qdf.Connect = "ODBC;DSN=Demo;Trusted_Connection=Yes;"
qdf.SQL = "EXEC dbo.Stp_FIX_RPT_Sname " & IdValueToProcess
qdf.Close
Set qdf = Nothing
End Sub
Sub Stp_Fname(MySubjID As Integer)
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Dim IdValueToProcess As Integer
IdValueToProcess = MySubjID
Set qdf = CurrentDb.CreateQueryDef("")
qdf.ReturnsRecords = True
qdf.Connect = "ODBC;DSN=Demo;Trusted_Connection=Yes;"
qdf.SQL = "EXEC dbo.Stp_FIX_RPT_Fname " & IdValueToProcess
qdf.Close
Set qdf = Nothing
End Sub
Sub Stp_HIS_001(MySubjID As Integer)
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Dim IdValueToProcess As Integer
IdValueToProcess = MySubjID
Set qdf = CurrentDb.CreateQueryDef("")
qdf.ReturnsRecords = True
qdf.Connect = "ODBC;DSN=Demo;Trusted_Connection=Yes;"
qdf.SQL = "EXEC dbo_Stp_FIX_RPT_Comments_His_001 " & IdValueToProcess
qdf.Close
Set qdf = Nothing
End Sub
SP's created on the server
Code:
USE DEMO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date: 17/07/2017
-- Description: Used to replace text in the FLX Academic Report Comment
-- =============================================
CREATE PROCEDURE Stp_FIX_FLX_RPT_Comments_Sname
-- Add the parameters for the stored procedure here
@ID_Subj int = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE R
SET R.Comment = REPLACE(rtrim(Comment), 'Sname', rtrim(S.Name_First))
from FLX_RPT_Results R
INNER JOIN STU_STUDENT S
ON S.ID_Student = R.ID_Student
WHERE R.ID_FLX_RPT_Subject = @ID_Subj
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date: 17/07/2017
-- Description: Used to replace text in the FLX Academic Report Comment
-- =============================================
CREATE PROCEDURE Stp_FIX_FLX_RPT_Comments_Fname
-- Add the parameters for the stored procedure here
@ID_Subj int = 0
AS
BEGIN
--DECLARE @ID_Subj int = 11
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE R
SET R.Comment = REPLACE(rtrim(Comment), 'Fname', rtrim(S.Name_First) +' ' + rtrim(S.Name_Surname))
from FLX_RPT_Results R
INNER JOIN STU_STUDENT S
ON S.ID_Student = R.ID_Student
WHERE R.ID_FLX_RPT_Subject = @ID_Subj
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date: 17/07/2017
-- Description: Used to replace text in the FLX Academic Report Comment
-- =============================================
CREATE PROCEDURE Stp_FIX_FLX_RPT_Comments_His_001
-- Add the parameters for the stored procedure here
@ID_Subj int = 0
AS
BEGIN
--DECLARE @ID_Subj int = 11
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- His / Her
UPDATE R
SET R.Comment = REPLACE(rtrim(Comment), 'his', 'her')
from FLX_RPT_Results R
INNER JOIN STU_STUDENT S
ON S.ID_Student = R.ID_Student
where S.Pers_Gender = 'Female' and R.ID_FLX_RPT_Subject = @ID_Subj
END
GO
-- =============================================
-- Author:
-- Create date: 17/07/2017
-- Description: Used to replace text in the FLX Academic Report Comment
-- =============================================
CREATE PROCEDURE Stp_FIX_FLX_RPT_Comments_Him_001
-- Add the parameters for the stored procedure here
@ID_Subj int = 0
AS
BEGIN
--DECLARE @ID_Subj int = 11
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE R
SET R.Comment = REPLACE(rtrim(Comment), ' him ', ' her ')
from FLX_RPT_Results R
INNER JOIN STU_STUDENT S
ON S.ID_Student = R.ID_Student
where S.Pers_Gender = 'Female' and R.ID_FLX_RPT_Subject = @ID_Subj
END
GO
-- =============================================
-- Author:
-- Create date: 17/07/2017
-- Description: Used to replace text in the FLX Academic Report Comment
-- =============================================
CREATE PROCEDURE Stp_FIX_FLX_RPT_Comments_Him_002
-- Add the parameters for the stored procedure here
@ID_Subj int = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE R
SET R.Comment = REPLACE(rtrim(Comment), '>him<', '>her<')
from FLX_RPT_Results R
INNER JOIN STU_STUDENT S
ON S.ID_Student = R.ID_Student
where S.Pers_Gender = 'Female' and R.ID_FLX_RPT_Subject = @ID_Subj
END
GO
Last edited: