Problem applying Case statement

jmersing

Well-known Member
Joined
Apr 14, 2004
Messages
887
What I'm trying to do is have the sub call the underlying query and apply the case statement to the where parameter of the query, based on the selction in the option group. I would also like to show all of the records as the default value, then apply the case statement only if one of the option group controls are checked. My query is a crosstab query, is that the reason this does not work?

Here is the query I am calling:
TRANSFORM Count(tblOut.OutID)/active AS Cnt
SELECT tblOut.txtDept, tblOut.RelatedEvent, qryAllOut.active AS Active, Count(tblOut.OutID) AS Out, out/active AS Total FROM qryAllOut INNER JOIN tblOut ON qryAllOut.Dept = tblOut.txtDept GROUP BY tblOut.txtDept, tblOut.RelatedEvent, qryAllOut.active PIVOT Format([CallDate],"ddd") In ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

Here is the Sub:
Private Sub Form_Open(Cancel As Integer)
Dim strsql As String

Select Case fraEvent
Dim relatedevent As String

Case 1
relatedevent = "NA"
Case 2
relatedevent = "Severe Weather"
Case 3
relatedevent = "Sports Event"
Case 4
relatedevent = "Holiday"
Case 5
relatedevent = "Worked Overtime"
Case 6
relatedevent = "Local Incident"
Case 7
relatedevent = "Traffic"
End Select

strsql = "SELECT * " _
& "FROM qrycrosstab " _
& "WHERE relatedevent " & relatedevent & ""

Forms!frmplan.Form.RecordSource = strsql

End Sub

Thanks!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,221,816
Messages
6,162,149
Members
451,746
Latest member
samwalrus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top