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 / May 2007

Tip: Looking for answers? Try searching our database.

Filtering a subform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy - 15 May 2007 14:54 GMT
I have run into problems in creating a records database for a scout group I
work with.
I have a form allowing me to select any number of people via a yes/no box.
The lists of people appear in a subform named subActiveMembers
The people are grouped in sections and I have tabs across the top of the
form to permit switching between sections.
I tried to do this by having some VBA that applied a filter on the section
depending upon the tab clicked.
My problem is that I cannot seem to get the filter to work.
I can insert the SQL in the subform (despite getting an error saying that I
cannot assign a value to the object) but I cannot activate the filter.
I have spent all day at this and it is driving me nuts.
VBA is listed below.
Any help would be very gratefully received.

Regards

Andy

Private Sub TabCtl0_Change()

'On selection of a tab, apply a filter based upon the value of that tab

Dim strSQL As String

strSQL = " SELECT tblMemberSelection.* " _
           & " FROM tblMemberSelection " _
           & " WHERE ((tblMemberSelection.Section)="

Select Case Me.TabCtl0
    Case 0: strSQL = strSQL & """Beavers - Hudson"""
    Case 1: strSQL = strSQL & """Beavers - McKenzie"""
    Case 2: strSQL = strSQL & """Cubs - Arran"""
    Case 3: strSQL = strSQL & """Cubs - Skye"""
    Case 4: strSQL = strSQL & """Scouts"""
    Case 5: strSQL = strSQL & """Explorers"""
    Case 6: strSQL = strSQL & """Network"""
    Case 7: strSQL = strSQL & """Group : Leader"""
    Case 8: strSQL = strSQL & """Group : Fellowship"""
    Case 9: strSQL = strSQL & """Group Executive"""
End Select

strSQL = strSQL & ");"

Me!subActiveMembers.Form.Filter = strSQL
Me!subActiveMembers.Form.FilterOn = True

Me.Refresh

End Sub
Carl Rapson - 15 May 2007 16:36 GMT
>I have run into problems in creating a records database for a scout group I
>work with.
[quoted text clipped - 46 lines]
>
> End Sub

A filter should be just the WHERE clause of an SQL statement (without the
word WHERE). Remove everything up to and including WHERE and try that.

An alternative is to actually change the RecordSource of the subform. In
that case, the full SQL statement would be used.

Carl Rapson
Andy - 16 May 2007 08:17 GMT
> A filter should be just the WHERE clause of an SQL statement (without the
> word WHERE). Remove everything up to and including WHERE and try that.
>
> An alternative is to actually change the RecordSource of the subform. In
> that case, the full SQL statement would be used.

Thanks for the reply.

I did try to change the child item of the subform to a query an
prgramatically changing that underlying query depending upon the tab clicked
but, although the query changes the subform does not refresh.

The extra SQL in the filter is a hangover from that. Bad programming on my
part and a bit embarassing to post it to a global forum for all to see
without deleting it. Oooops.

Andy
 
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.