D
Drew
I am trying to build a report application for reporting off of SQL Server.
I have built my form for collecting the report criteria, and have built the
report. Now I am having problems interfacing my dynamic stored procedure
with the ADP.
Here is my Stored Procedure,
CREATE PROCEDURE spEventsByCatRegNoDate (@WHEREClause varchar(255))
AS
-- Create a variable @SQLStatement
DECLARE @SQLStatement varchar(1500)
-- Enter the dynamic SQL statement into the variable @SQLStatement
SELECT @SQLStatement = "SELECT UID, E.RegNo, ResEPI, CC.CliFName,
CC.CliLName, CC.CliMM, AggressorRegNo, AggResEPI, CA.CliFName AS AggFName,
CA.CliLName AS AggLName, CA.CliMM AS AggMM, Category, SubCategory,
EventDate, EventTime, Situation, EventBuilding,
Location, IllnessInjury, BodyPart, Mobility, Severity, Risk, MedAttnNeeded,
RiskMgrNotified, DRVDReport, BAR,
DeathReview, AddlInHouse, DGSDRMNotified, EmergencyCenter,
InfirmaryAdmission, RescueSquad, HospitializationRequired,
FallPrecaution, RepeatFaller, Litigations, Claims, HurtByAggressor,
EventClosed, PlanOfCorrection, Comments
FROM Events E INNER JOIN CliCore.dbo.tblClients CC ON E.RegNo = CC.RegNo
INNER JOIN
EventCat C ON E.EventCatID = C.CatID INNER JOIN EventSubCat SC ON
E.EventSubCatID = SC.SubCatID INNER JOIN
CliCore.dbo.tblClients CA ON E.AggressorRegNo = CA.RegNo INNER JOIN
Situation S ON E.EventSituationID = S.SituationID INNER JOIN
Location L ON E.EventLocationID = L.LocationID INNER JOIN
IllnessInjury II ON E.EventIllnessInjuryID = II.IllnessInjuryID INNER JOIN
BodyPart BP ON E.InjuredBodyPartID = BP.BodyPartID INNER JOIN
Mobility M ON E.EventMobilityID = M.MobilityID INNER JOIN
Severity SV ON E.EventSeverityID = SV.SeverityID INNER JOIN
Risk R ON E.EventRiskID = R.RiskID " + @WHEREClause
-- Execute the SQL statement
EXEC(@SQLStatement)
GO
The form has 7 form elements, Register #, Operator, Aggressor Register #,
Category, Subcategory, Start Date, End Date. I am trying to build this
report so that users only have to enter Register # and get a report, or they
can enter data into all of the form elements, or any combination of form
elements. I have built dynamic SQL statements in ASP before, and thought I
could bring that logic over to ADP's, but am currently having issues.
Here is the report's OnOpen event,
DoCmd.OpenForm "frmEventsByCatRegNoDate", acNormal, , , , acDialog
Dim strRecordSource As String
Dim RegNo As Integer
Dim Operator As String
Dim AggRegNo As Integer
Dim CatID As Integer
Dim SubCatID As Integer
Dim StartDate As Date
Dim EndDate As Date
RegNo = 0
If (Forms!frmEventsByCatRegNoDate.txtRegNo) <> "" Then
RegNo = Forms!frmEventsByCatRegNoDate.txtRegNo
End If
Operator = ""
If (Forms!frmEventsByCatRegNoDate.ddlOperator) <> "" Then
Operator = Forms!frmEventsByCatRegNoDate.ddlOperator
End If
AggRegNo = 0
If (Forms!frmEventsByCatRegNoDate.txtAggRegNo) <> "" Then
AggRegNo = Forms!frmEventsByCatRegNoDate.txtAggRegNo
End If
CatID = 0
If (Forms!frmEventsByCatRegNoDate.ddlCatID) <> "" Then
CatID = Forms!frmEventsByCatRegNoDate.ddlCatID
End If
SubCatID = 0
If (Forms!frmEventsByCatRegNoDate.ddlSubCatID) <> "" Then
SubCatID = Forms!frmEventsByCatRegNoDate.ddlSubCatID
End If
StartDate = 1 / 1 / 1900
If (Forms!frmEventsByCatRegNoDate.txtStartDate) <> "" Then
StartDate = Forms!frmEventsByCatRegNoDate.txtStartDate
End If
EndDate = 1 / 1 / 1900
If (Forms!frmEventsByCatRegNoDate.txtEndDate) <> "" Then
EndDate = Forms!frmEventsByCatRegNoDate.txtEndDate
End If
'For all records
strRecordSource = "Exec [spEventsByCatRegNoDate] " & "''"
If RegNo <> 0 Then
strRecordSource = "Exec [spEventsByCatRegNoDate] " & "'WHERE E.RegNo
= " & RegNo
If AggRegNo <> 0 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
If Operator <> "" Then
strRecordSource = strRecordSource & " " & Operator & "
E.AggressorRegNo = " & AggRegNo & "'"
Else
strRecordSource = strRecordSource & "E.AggressorRegNo = " &
AggRegNo
End If
End If
End If
If CatID <> 0 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
strRecordSource = "'" & strRecordSource & "AND E.CatID = " &
CatID & "'"
Else
strRecordSource = strRecordSource & "E.CatID = " & CatID
End If
End If
If SubCatID <> 0 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
strRecordSource = strRecordSource & "AND E.SubCatID = " &
SubCatID
Else
strRecordSource = strRecordSource & "E.SubCatID = " & SubCatID
End If
End If
If StartDate <> 1 / 1 / 1900 And EndDate <> 1 / 1 / 1900 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
strRecordSource = strRecordSource & "AND EventDate BETWEEN '" &
StarDate & "' AND '" & EndDate & "'"
Else
strRecordSource = strRecordSource & "EventDate BETWEEN '" &
StarDate & "' AND '" & EndDate & "'"
End If
End If
End If
Me.RecordSource = strRecordSource
DoCmd.Close acForm, "frmEventsByCatRegNoDate"
Can anyone help me out with this issue? I just need some help building my
query so that it works.
Thanks,
Drew Laing
I have built my form for collecting the report criteria, and have built the
report. Now I am having problems interfacing my dynamic stored procedure
with the ADP.
Here is my Stored Procedure,
CREATE PROCEDURE spEventsByCatRegNoDate (@WHEREClause varchar(255))
AS
-- Create a variable @SQLStatement
DECLARE @SQLStatement varchar(1500)
-- Enter the dynamic SQL statement into the variable @SQLStatement
SELECT @SQLStatement = "SELECT UID, E.RegNo, ResEPI, CC.CliFName,
CC.CliLName, CC.CliMM, AggressorRegNo, AggResEPI, CA.CliFName AS AggFName,
CA.CliLName AS AggLName, CA.CliMM AS AggMM, Category, SubCategory,
EventDate, EventTime, Situation, EventBuilding,
Location, IllnessInjury, BodyPart, Mobility, Severity, Risk, MedAttnNeeded,
RiskMgrNotified, DRVDReport, BAR,
DeathReview, AddlInHouse, DGSDRMNotified, EmergencyCenter,
InfirmaryAdmission, RescueSquad, HospitializationRequired,
FallPrecaution, RepeatFaller, Litigations, Claims, HurtByAggressor,
EventClosed, PlanOfCorrection, Comments
FROM Events E INNER JOIN CliCore.dbo.tblClients CC ON E.RegNo = CC.RegNo
INNER JOIN
EventCat C ON E.EventCatID = C.CatID INNER JOIN EventSubCat SC ON
E.EventSubCatID = SC.SubCatID INNER JOIN
CliCore.dbo.tblClients CA ON E.AggressorRegNo = CA.RegNo INNER JOIN
Situation S ON E.EventSituationID = S.SituationID INNER JOIN
Location L ON E.EventLocationID = L.LocationID INNER JOIN
IllnessInjury II ON E.EventIllnessInjuryID = II.IllnessInjuryID INNER JOIN
BodyPart BP ON E.InjuredBodyPartID = BP.BodyPartID INNER JOIN
Mobility M ON E.EventMobilityID = M.MobilityID INNER JOIN
Severity SV ON E.EventSeverityID = SV.SeverityID INNER JOIN
Risk R ON E.EventRiskID = R.RiskID " + @WHEREClause
-- Execute the SQL statement
EXEC(@SQLStatement)
GO
The form has 7 form elements, Register #, Operator, Aggressor Register #,
Category, Subcategory, Start Date, End Date. I am trying to build this
report so that users only have to enter Register # and get a report, or they
can enter data into all of the form elements, or any combination of form
elements. I have built dynamic SQL statements in ASP before, and thought I
could bring that logic over to ADP's, but am currently having issues.
Here is the report's OnOpen event,
DoCmd.OpenForm "frmEventsByCatRegNoDate", acNormal, , , , acDialog
Dim strRecordSource As String
Dim RegNo As Integer
Dim Operator As String
Dim AggRegNo As Integer
Dim CatID As Integer
Dim SubCatID As Integer
Dim StartDate As Date
Dim EndDate As Date
RegNo = 0
If (Forms!frmEventsByCatRegNoDate.txtRegNo) <> "" Then
RegNo = Forms!frmEventsByCatRegNoDate.txtRegNo
End If
Operator = ""
If (Forms!frmEventsByCatRegNoDate.ddlOperator) <> "" Then
Operator = Forms!frmEventsByCatRegNoDate.ddlOperator
End If
AggRegNo = 0
If (Forms!frmEventsByCatRegNoDate.txtAggRegNo) <> "" Then
AggRegNo = Forms!frmEventsByCatRegNoDate.txtAggRegNo
End If
CatID = 0
If (Forms!frmEventsByCatRegNoDate.ddlCatID) <> "" Then
CatID = Forms!frmEventsByCatRegNoDate.ddlCatID
End If
SubCatID = 0
If (Forms!frmEventsByCatRegNoDate.ddlSubCatID) <> "" Then
SubCatID = Forms!frmEventsByCatRegNoDate.ddlSubCatID
End If
StartDate = 1 / 1 / 1900
If (Forms!frmEventsByCatRegNoDate.txtStartDate) <> "" Then
StartDate = Forms!frmEventsByCatRegNoDate.txtStartDate
End If
EndDate = 1 / 1 / 1900
If (Forms!frmEventsByCatRegNoDate.txtEndDate) <> "" Then
EndDate = Forms!frmEventsByCatRegNoDate.txtEndDate
End If
'For all records
strRecordSource = "Exec [spEventsByCatRegNoDate] " & "''"
If RegNo <> 0 Then
strRecordSource = "Exec [spEventsByCatRegNoDate] " & "'WHERE E.RegNo
= " & RegNo
If AggRegNo <> 0 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
If Operator <> "" Then
strRecordSource = strRecordSource & " " & Operator & "
E.AggressorRegNo = " & AggRegNo & "'"
Else
strRecordSource = strRecordSource & "E.AggressorRegNo = " &
AggRegNo
End If
End If
End If
If CatID <> 0 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
strRecordSource = "'" & strRecordSource & "AND E.CatID = " &
CatID & "'"
Else
strRecordSource = strRecordSource & "E.CatID = " & CatID
End If
End If
If SubCatID <> 0 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
strRecordSource = strRecordSource & "AND E.SubCatID = " &
SubCatID
Else
strRecordSource = strRecordSource & "E.SubCatID = " & SubCatID
End If
End If
If StartDate <> 1 / 1 / 1900 And EndDate <> 1 / 1 / 1900 Then
If strRecordSource <> "Exec [spEventsByCatRegNoDate] " & "''" Then
strRecordSource = strRecordSource & "AND EventDate BETWEEN '" &
StarDate & "' AND '" & EndDate & "'"
Else
strRecordSource = strRecordSource & "EventDate BETWEEN '" &
StarDate & "' AND '" & EndDate & "'"
End If
End If
End If
Me.RecordSource = strRecordSource
DoCmd.Close acForm, "frmEventsByCatRegNoDate"
Can anyone help me out with this issue? I just need some help building my
query so that it works.
Thanks,
Drew Laing