G
Guest
I have a table with many fields, but I want to use the following fields to
pull data into a report: State, county, PT, ST, OT, VRE. State & County are
a list of all states/counties. PT, ST, OT and VRE are yes/no. The are
filled in by a check box via form. I'm trying to create a report from a form
based on combo boxes to show selected data.
Right now, the report works for choosing state(s) or counties. However, how
can I rewrite this code to be able to choose PT from a dropdown and only show
those records that have PT checked yes?
Here is my code thus far:
Private Sub Command162_Click()
Dim dbs As Database, SqlStr As String
Dim qdf As QueryDef
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryCSDReport")
Dim sqlWhereString As String
Dim sqlWhereTrue As Integer
Dim sqlStart As String
Dim stateString As String
Dim countyString As String
Dim specialtyString As String
SqlStr = "SELECT [Facility Name] , [Tax ID], STATE, City, [Street
Address], STATE, Zip, County, [Phone #] , [Physical Therapy (PT)],
[Occupational Therapy (OT)], [Speech Therapy (ST)] , MRSA, VRE, TB,
[HIV/AIDS], [Private Rooms], [Total Parental Nutrition (TPN)], [Central
Lines], [PICC Lines] , [Continuous Heparin Infusion], [Intrathecal
Medications], Chemotherapy, [Computerized Clinical Information], [Amputation
Recovery], [Peritoneal Dialysis], Hospice, [HIV/ARC Dementia], Hemodialysis,
[Alzheimer/ Dementia Care], TBI, [Complex Care], [Cognitive Therapy], Chemo,
[Cardiac Rehab], [Behavioral Management], Bariatric, [Bariatric Weight
Limit], [Wall Oxygen/Suction Set-Ups], [Weaning/Decannulation], [Trach - New
and Chronic] , Vents, [Adult Day], [Respite Care], MS, [24 hour admissions],
Pediatric, [Palliative Care] , [IV Pain Meds], [PCA Pumps], [Wound Care
Team], [Whirlpool Therapy (Full Tank)], [Whirlpool Therapy (Extremity Tank)],
[Wound VAC Therapy] , [Estin/Pulse Lavage:]" & _
"FROM tblCSD "
For i = 0 To Me.STATE.ListCount - 1
If (Me.STATE.Selected(i) = True) Then
stateString = stateString & "State = '" & Me.STATE.Column(0, i)
& "' Or "
End If
Next i
If Len(stateString) > 0 Then
sqlWhereTrue = 1
sqlWhereString = sqlWhereString & " (" & Left(stateString,
Len(stateString) - 4) & ") AND "
End If
For i = 0 To Me.County.ListCount - 1
If (Me.County.Selected(i) = True) Then
countyString = countyString & "County = '" & Me.County.Column(0,
i) & "' Or "
End If
Next i
If Len(countyString) > 0 Then
sqlWhereTrue = 1
sqlWhereString = sqlWhereString & " (" & Left(countyString,
Len(countyString) - 4) & ") AND "
End If
For i = 0 To Me.Speciality.ListCount - 1
If (Me.Speciality.Selected(i) = True) Then
Speciality = specialityString & "Speciality = '" &
Me.Speciality.Column(0, i) & "' Or "
End If
Next i
If Len(specialityString) > 0 Then
sqlWhereTrue = 1
sqlWhereString = sqlWhereString & " (" & Left(specialityString,
Len(specialtyString) - 4) & ") AND "
End If
If sqlWhereTrue = 1 Then
SqlStr = SqlStr & " WHERE " & Left(sqlWhereString,
Len(sqlWhereString) - 5)
End If
CurrentDb.QueryDefs("qryCSDReport").SQL = SqlStr
DoCmd.OpenQuery ("qryCSDReport")
End Sub
pull data into a report: State, county, PT, ST, OT, VRE. State & County are
a list of all states/counties. PT, ST, OT and VRE are yes/no. The are
filled in by a check box via form. I'm trying to create a report from a form
based on combo boxes to show selected data.
Right now, the report works for choosing state(s) or counties. However, how
can I rewrite this code to be able to choose PT from a dropdown and only show
those records that have PT checked yes?
Here is my code thus far:
Private Sub Command162_Click()
Dim dbs As Database, SqlStr As String
Dim qdf As QueryDef
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryCSDReport")
Dim sqlWhereString As String
Dim sqlWhereTrue As Integer
Dim sqlStart As String
Dim stateString As String
Dim countyString As String
Dim specialtyString As String
SqlStr = "SELECT [Facility Name] , [Tax ID], STATE, City, [Street
Address], STATE, Zip, County, [Phone #] , [Physical Therapy (PT)],
[Occupational Therapy (OT)], [Speech Therapy (ST)] , MRSA, VRE, TB,
[HIV/AIDS], [Private Rooms], [Total Parental Nutrition (TPN)], [Central
Lines], [PICC Lines] , [Continuous Heparin Infusion], [Intrathecal
Medications], Chemotherapy, [Computerized Clinical Information], [Amputation
Recovery], [Peritoneal Dialysis], Hospice, [HIV/ARC Dementia], Hemodialysis,
[Alzheimer/ Dementia Care], TBI, [Complex Care], [Cognitive Therapy], Chemo,
[Cardiac Rehab], [Behavioral Management], Bariatric, [Bariatric Weight
Limit], [Wall Oxygen/Suction Set-Ups], [Weaning/Decannulation], [Trach - New
and Chronic] , Vents, [Adult Day], [Respite Care], MS, [24 hour admissions],
Pediatric, [Palliative Care] , [IV Pain Meds], [PCA Pumps], [Wound Care
Team], [Whirlpool Therapy (Full Tank)], [Whirlpool Therapy (Extremity Tank)],
[Wound VAC Therapy] , [Estin/Pulse Lavage:]" & _
"FROM tblCSD "
For i = 0 To Me.STATE.ListCount - 1
If (Me.STATE.Selected(i) = True) Then
stateString = stateString & "State = '" & Me.STATE.Column(0, i)
& "' Or "
End If
Next i
If Len(stateString) > 0 Then
sqlWhereTrue = 1
sqlWhereString = sqlWhereString & " (" & Left(stateString,
Len(stateString) - 4) & ") AND "
End If
For i = 0 To Me.County.ListCount - 1
If (Me.County.Selected(i) = True) Then
countyString = countyString & "County = '" & Me.County.Column(0,
i) & "' Or "
End If
Next i
If Len(countyString) > 0 Then
sqlWhereTrue = 1
sqlWhereString = sqlWhereString & " (" & Left(countyString,
Len(countyString) - 4) & ") AND "
End If
For i = 0 To Me.Speciality.ListCount - 1
If (Me.Speciality.Selected(i) = True) Then
Speciality = specialityString & "Speciality = '" &
Me.Speciality.Column(0, i) & "' Or "
End If
Next i
If Len(specialityString) > 0 Then
sqlWhereTrue = 1
sqlWhereString = sqlWhereString & " (" & Left(specialityString,
Len(specialtyString) - 4) & ") AND "
End If
If sqlWhereTrue = 1 Then
SqlStr = SqlStr & " WHERE " & Left(sqlWhereString,
Len(sqlWhereString) - 5)
End If
CurrentDb.QueryDefs("qryCSDReport").SQL = SqlStr
DoCmd.OpenQuery ("qryCSDReport")
End Sub