Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / November 2006

Tip: Looking for answers? Try searching our database.

Combo and Select Case filter not working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DubboPete - 27 Nov 2006 22:09 GMT
Hi all,

I have a form which is the basis for a report.   On the form I have a
list of facilities in Combo38.   Then, once a facility has been
selected, there are six choices in a frame to further filter down the
records.

The filter is supposed to find all records where, for instance, the
facility is Drug and Alcohol Unit, and the category is "Continuum Of
Care".

Once selected, I then click a command button to preview the filtered
report.   The only problem is, the frame's filter part is not
'filtering' !   The combo box filter seems to be working, but I see all
records for the particular facility, not just the selected choice in
the frame.

Here's the code:

Private Sub Command21_Click()

Dim strField As String
Dim strWhere As String

Select Case Me.[Frame9]
   Case 1
       strField = "[Continuum Of Care]"
   Case 2
       strField = "[Leadership & Management]"
   Case 3
       strField = "[Human Resources Management]"
   Case 4
       strField = "[Information Management]"
   Case 5
       strField = "[Safe Practice & Environment]"
   Case 6
       strField = "[Service Delivery (Area Office only)]"
End Select

strWhere = BuildCriteria("FacilityID", dbLong, Me.Combo38.Value)

If strField = "Yes" Then
       strWhere = strWhere & " AND " & BuildCriteria(strField,
dbBoolean, True)
End If

DoCmd.OpenReport "RptEquipSum1", acViewPreview, , strWhere

End Sub

Can anybody see any flaws in the code, and if not, why aint it
filtering properly??  :-)

DubboPete
SteveS - 27 Nov 2006 22:42 GMT
DubboPete,

You have a Select Case where you set "[strField ]" = ......... (to
everything except YES), then you check if "[strField]"= "Yes".

Why do you check for "Yes" (If strField = "Yes" Then)  when it appears that
"[strField ] " will never be set to "Yes"????

Signature

Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)

> Hi all,
>
[quoted text clipped - 50 lines]
>
> DubboPete
DubboPete - 27 Nov 2006 22:58 GMT
Thanks Steve, made sense out of it now, and got it filtering
correctly...
I created another string StrWhere2, and the resulting code changes at
execution point towards the end.

Here's the corrected code:

Dim strField As String
Dim strWhere As String
Dim strWhere2 As String

Select Case Me.[Frame9]
   Case 1
       strField = "[Continuum Of Care]"
   Case 2
       strField = "[Leadership & Management]"
   Case 3
       strField = "[Human Resources Management]"
   Case 4
       strField = "[Information Management]"
   Case 5
       strField = "[Safe Practice & Environment]"
   Case 6
       strField = "[Service Delivery (Area Office only)]"
End Select

strWhere = BuildCriteria("FacilityID", dbLong, Me.Combo38.Value)
strWhere2 = strWhere & " AND " & BuildCriteria(strField, dbBoolean,
True)

> DubboPete,
>
[quoted text clipped - 64 lines]
> >
> > DubboPete
SteveS - 28 Nov 2006 01:05 GMT
Great.

BTW, I don't know what   "BuildCriteria( ) " does, but since you don't have
the IF() statement, you could just use

strWhere = BuildCriteria("FacilityID", dbLong, Me.Combo38.Value)
strWhere = strWhere & " AND " & BuildCriteria(strField, dbBoolean,True)

You don't really need to use "strWhere2" since you are concatenating the two
lines.

Also, if you want to save some typing, you don't need to use ".Value"
(as in  "Me.Combo38.Value") because Value is the default property.

You can just use    "Me.Combo38" .

Good luck
Signature

Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)

> Thanks Steve, made sense out of it now, and got it filtering
> correctly...
[quoted text clipped - 94 lines]
> > >
> > > DubboPete
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.