Put the Debug line at the bottom of the procedure just above:[color=blue]
> Forms(Me.Name)("sfrmRoundUpSearchResults").Form.Fi lter =[/color]
strWhere
Where you have it now displays nothing because strWhere has not yet been set
to anything. You can also move the line around to different points in the
procedure to see what the Where clause looks like at each point. This is
only used for development, however and should be commented out for
production as it uses up processing time.
--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org
"William Wisnieski" <wwisnieski@admissions.umass.edu> wrote in message
news:3fe9bda2$1@news-1.oit.umass.edu...[color=blue]
> Roger,
>
> The debug idea sounds great. I'm trying it right now with no luck though.
> nothing shows up in the immediate window. This is what I have:
>
> If Len(Me.lstCollege & "") > 0 Then
> Debug.Print strWhere
> strWhere = "[College] = '" & Me.lstCollege & "'"
> End If
>
> I have set a breakpoint at strWhere = "[College] = '" & Me.lstCollege &[/color]
"'"[color=blue]
> and opened the immediate window. I select the first two criteria on the
> form and click the show results button and the line strWhere =[/color]
"[College][color=blue]
> = '" & Me.lstCollege & "'" gets highlighted in yellow but nothing shows up
> in the immediate window.
>
> Sorry for my numerous posts trying to get this thing done!
>
> William
>
>
>
>
>
>
>
>
> "William Wisnieski" <wwisnieski@admissions.umass.edu> wrote in message
> news:3fe9b1b8$1@news-1.oit.umass.edu...[color=green]
> > Whoa, sorry about that....I see now what sections you are referring
> > to.....I'm working through it right now and will let you know how I make
> > out.
> >
> > Thanks again....
> >
> > William
> >
> >
> > "William Wisnieski" <wwisnieski@admissions.umass.edu> wrote in message
> > news:3fe9b01b$1@news-1.oit.umass.edu...[color=darkred]
> > > Roger....thanks again.
> > >
> > > Sorry for the confusion. Regarding the filtering problem, all records[/color][/color]
> are[color=green][color=darkred]
> > > being returned. Also, I don't quite understand the If Len(strWhere).[/color][/color]
> I'm[color=green][color=darkred]
> > > not sure which sections you are referring to. Should I be using that
> > > instead of say, If Len(Me.lstCollege & "") > 0[/color][/color][/color]
Then.....................[color=blue][color=green][color=darkred]
> > >
> > > William
> > >
> > >
> > > "Roger Carlson" <NO-carlsoro-SPAM@hotmail.com> wrote in message
> > > news:%23%230dptiyDHA.1764@TK2MSFTNGP10.phx.gbl...
> > > > When you say it does not filter, do you mean All records are[/color][/color][/color]
returned[color=blue]
> or[color=green][color=darkred]
> > > No
> > > > records are returned?
> > > >
> > > > Well, I see some obvious problems, none of which may be the major[/color][/color]
> cause.[color=green][color=darkred]
> > > >
> > > > 1) This section:
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "[AcadPlan] IN ("
> > > >
> > > > should have an AND like so:
> > > >
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & " AND [AcadPlan] IN ("
> > > >
> > > > 2) This section:
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "And [EMPLID] = '" &[/color][/color][/color]
Me.txtEMPLID[color=blue]
> &[color=green][color=darkred]
> > > "'"
> > > > > Else
> > > > > strWhere = "[EMPLID] = " & Me.txtEMPLID
> > > > >
> > > > > End If
> > > > is using two different datatypes. If EMPLID is text, the first[/color][/color][/color]
should[color=blue][color=green]
> > be[color=darkred]
> > > > used, if it is numeric, the second should be used
> > > >
> > > > 3) This is not causing a problem yet, but may in the future. If you[/color]
> > have[color=darkred]
> > > a
> > > > person with a Last name of O'Brien, this code will fail:
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "And [Last] = '" & Me.txtLast &[/color][/color]
> "'"[color=green][color=darkred]
> > > > > Else
> > > > > strWhere = "[Last] = '" & Me.txtLast & "'"
> > > > > End If
> > > >
> > > > To fix, replace each apostrophe (') with TWO quotes ("")
> > > >
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "And [Last] = """ & Me.txtLast &[/color]
> > """"[color=darkred]
> > > > > Else
> > > > > strWhere = "[Last] = """ & Me.txtLast & """"
> > > > > End If
> > > >
> > > > Now, as I said, these may not be the cause of the problem at hand.[/color][/color]
> The[color=green][color=darkred]
> > > best
> > > > thing to do in a situation like this is to put the following line:
> > > >
> > > > Debug.Print strWhere
> > > >
> > > > just before the filtering line. Then put a break point on the first
> > > filter
> > > > line. The code will stop before the filter executes and if you look[/color][/color]
> in[color=green][color=darkred]
> > > the
> > > > Debug (Immediate) window, you will see exactly what your Where[/color][/color][/color]
clause[color=blue][color=green][color=darkred]
> > > looks
> > > > like. You can even cut and paste it into a query and see what it is
> > > > acutally returning or what error messages it produces.
> > > >
> > > > HTH
> > > >
> > > > --
> > > > --Roger Carlson
> > > >
www.rogersaccesslibrary.com
> > > > Reply to: Roger dot Carlson at Spectrum-Health dot Org
> > > >
> > > > "William Wisnieski" <wwisnieski@admissions.umass.edu> wrote in[/color][/color][/color]
message[color=blue][color=green][color=darkred]
> > > > news:3fe894e4$1@news-1.oit.umass.edu...
> > > > > Thanks Roger. I used your code and it works great. I'm trying to
> > > modify
> > > > it
> > > > > now for two reasons. Now, I have to add some more search criteria
> > > (State,
> > > > > HonorsCollege, EMPLID, LastName) on the main form. Second, I need[/color][/color]
> the[color=green][color=darkred]
> > > > user
> > > > > to be able to select from the college list without being required[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> > > > select
> > > > > from the AcadPlan list.
> > > > >
> > > > > Here's what I have that works so far:
> > > > >
> > > > > Private Sub cmdShowResults_Click()
> > > > > Me.sfrmRoundUpSearchResults.Visible = True
> > > > > Me.lblSubformInstructions.Visible = True
> > > > > Dim strWhere As String
> > > > > Dim rst As Recordset
> > > > >
> > > > > strWhere = strWhere & "[AcadPlan] IN ("
> > > > > For i = 0 To lstAcadPlan.ListCount - 1
> > > > > If lstAcadPlan.Selected(i) Then
> > > > > strWhere = strWhere & "'" & lstAcadPlan.Column(0, i) & "',[/color][/color][/color]
"[color=blue][color=green][color=darkred]
> > > > > End If
> > > > > Next i
> > > > > strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
> > > > >
> > > > > Forms(Me.Name)("sfrmRoundUpSearchResults").Form.Fi lter =[/color][/color]
> strWhere[color=green][color=darkred]
> > > > > Forms(Me.Name)("sfrmRoundUpSearchResults").Form.Fi lterOn =[/color][/color][/color]
True[color=blue][color=green][color=darkred]
> > > > >
> > > > > ==================================
> > > > >
> > > > > Now here is what I have added. The good news is it doesn't return[/color][/color]
> any[color=green][color=darkred]
> > > > > errors. The bad news is it doesn't filter any records:
> > > > >
> > > > > Private Sub cmdShowResults_Click()
> > > > > Me.sfrmRoundUpSearchResults.Visible = True
> > > > > Me.lblSubformInstructions.Visible = True
> > > > > Dim strWhere As String
> > > > > Dim rst As Recordset
> > > > >
> > > > > If Len(Me.lstCollege & "") > 0 Then
> > > > > strWhere = "[College] = '" & Me.lstCollege & "'"
> > > > > End If
> > > > >
> > > > > If Len(Me.lstAcadPlan & "") > 0 Then
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "[AcadPlan] IN ("
> > > > > For i = 0 To lstAcadPlan.ListCount - 1
> > > > > If lstAcadPlan.Selected(i) Then
> > > > > strWhere = strWhere & "'" & lstAcadPlan.Column(0, i) & "',[/color][/color][/color]
"[color=blue][color=green][color=darkred]
> > > > > End If
> > > > > Next i
> > > > > strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
> > > > > Else
> > > > > strWhere = "[AcadPlan] IN ("
> > > > > For i = 0 To lstAcadPlan.ListCount - 1
> > > > > If lstAcadPlan.Selected(i) Then
> > > > > strWhere = "'" & lstAcadPlan.Column(0, i) & "', "
> > > > > End If
> > > > > Next i
> > > > > strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
> > > > > End If
> > > > >
> > > > > If Len(Me.lstHonors & "") > 0 Then
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "And [HonorsCollege] = '" &
> > > Me.lstHonors
> > > > &
> > > > > "'"
> > > > > Else
> > > > > strWhere = "[HonorsCollege] = '" & Me.lstHonors & "'"
> > > > > End If
> > > > >
> > > > > End If
> > > > > If Len(Me.cboState & "") > 0 Then
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "And [State] = '" & Me.cboState[/color][/color][/color]
&[color=blue][color=green]
> > "'"[color=darkred]
> > > > > Else
> > > > > strWhere = "[State] = '" & Me.cboState & "'"
> > > > > End If
> > > > > End If
> > > > >
> > > > > If Len(Me.txtEMPLID & "") > 0 Then
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "And [EMPLID] = '" &[/color][/color][/color]
Me.txtEMPLID[color=blue]
> &[color=green][color=darkred]
> > > "'"
> > > > > Else
> > > > > strWhere = "[EMPLID] = " & Me.txtEMPLID
> > > > >
> > > > > End If
> > > > > End If
> > > > >
> > > > > If Len(Me.txtLast & "") > 0 Then
> > > > > If Len(strWhere) > 0 Then
> > > > > strWhere = strWhere & "And [Last] = '" & Me.txtLast &[/color][/color]
> "'"[color=green][color=darkred]
> > > > > Else
> > > > > strWhere = "[Last] = '" & Me.txtLast & "'"
> > > > > End If
> > > > > End If
> > > > >
> > > > > Forms(Me.Name)("sfrmRoundUpSearchResults").Form.Fi lter =[/color][/color]
> strWhere[color=green][color=darkred]
> > > > > Forms(Me.Name)("sfrmRoundUpSearchResults").Form.Fi lterOn =[/color][/color][/color]
True[color=blue][color=green][color=darkred]
> > > > >
> > > > > Thanks again for your help. It is much appreciated.
> > > > >
> > > > > William
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > "Roger Carlson" <NO-carlsoro-SPAM@hotmail.com> wrote in message
> > > > > news:ucPBGqMyDHA.2084@TK2MSFTNGP09.phx.gbl...
> > > > > > OK. Sorry, I missed a bit. Try this:
> > > > > >
> > > > > > strWhere = "Where [College] = '" & Me.lstCollege & "' and "
> > > > > > strWhere = strWhere & "[AcadPlan] IN ("
> > > > > > For i = 0 To lstAcadPlan.ListCount - 1
> > > > > > If lstAcadPlan.Selected(i) Then
> > > > > > strWhere = strWhere & "'" & lstAcadPlan.Column(0, i) &[/color][/color]
> "',[color=green]
> > "[color=darkred]
> > > > > > End If
> > > > > > Next i
> > > > > > strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
> > > > > >
> > > > > > --Roger Carlson
> > > > > >
www.rogersaccesslibrary.com
> > > > > > Reply to: Roger dot Carlson at Spectrum-Health dot Org
> > > > > >
> > > > > > "William Wisnieski" <wwisnieski@admissions.umass.edu> wrote in[/color]
> > message[color=darkred]
> > > > > > news:3fe7431e$1@news-1.oit.umass.edu...
> > > > > > > Thanks Roger,
> > > > > > >
> > > > > > > I tried your code. I get a run time error and when I go to[/color][/color]
> debug,[color=green][color=darkred]
> > > it
> > > > > > seems
> > > > > > > to have combined the college and academic plan. For example,
> > > strWhere
> > > > > > > filter should show "[College] = CAS and [AcadPlan] = Art, Or
> > > > Philosophy,
> > > > > > Or
> > > > > > > History". But it is showing [College]=CAS, Art, Philosophy,
> > > History."
> > > > > > >
> > > > > > > William
> > > > > > >
> > > > > > >
> > > > > > > "Roger Carlson" <NO-carlsoro-SPAM@hotmail.com> wrote in[/color][/color][/color]
message[color=blue][color=green][color=darkred]
> > > > > > > news:O7S%23fTKyDHA.3224@tk2msftngp13.phx.gbl...
> > > > > > > > On my website (see sig below) is a small sample database[/color][/color]
> called[color=green][color=darkred]
> > > > > > > > "CreateQueries2.mdb". Form 6 in this database illustrates[/color][/color][/color]
how[color=blue][color=green]
> > to[color=darkred]
> > > > > create
> > > > > > a
> > > > > > > > Where condition in code with a multi-select listbox. See[/color][/color][/color]
the[color=blue][color=green]
> > code[color=darkred]
> > > > > > behind
> > > > > > > > the form for details. In broad outline, it will work[/color][/color]
> something[color=green][color=darkred]
> > > like
> > > > > > this:
> > > > > > > >
> > > > > > > > For i = 0 To lstAcadPlan.ListCount - 1
> > > > > > > > If lstAcadPlan.Selected(i) Then
> > > > > > > > strWhere = strWhere & "'" & lstAcadPlan.Column(0, i)[/color][/color][/color]
&[color=blue][color=green]
> > "',[color=darkred]
> > > "
> > > > > > > > End If
> > > > > > > > Next i
> > > > > > > > strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
> > > > > > > >
> > > > > > > > This code loops through the values in the listbox. When it
> > > reaches
> > > > > one
> > > > > > > that
> > > > > > > > is selected, it adds to the Where clause. When it reaches[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > end,
> > > > it
> > > > > > > lops
> > > > > > > > the last comma off of the Where clause.
> > > > > > > >
> > > > > > > > (The actual syntax of the strWhere clause will vary[/color][/color][/color]
depending[color=blue]
> on[color=green][color=darkred]
> > > > > details
> > > > > > > of
> > > > > > > > your listbox control.)
> > > > > > > >
> > > > > > > > --
> > > > > > > > --Roger Carlson
> > > > > > > >
www.rogersaccesslibrary.com
> > > > > > > > Reply to: Roger dot Carlson at Spectrum-Health dot Org
> > > > > > > >
> > > > > > > >
> > > > > > > > "William Wisnieski" <wwisnieski@admissions.umass.edu> wrote[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > message
> > > > > > > > news:3fe710b9$1@news-1.oit.umass.edu...
> > > > > > > > > Hello Everyone,
> > > > > > > > >
> > > > > > > > > I have a main form with a datasheet subform that I use to[/color]
> > query[color=darkred]
> > > by
> > > > > > form.
> > > > > > > > > After the user selects two criteria on the main form and[/color]
> > clicks[color=darkred]
> > > > the
> > > > > > > > > cmdShowResults button on the main form, the subform[/color][/color][/color]
returns[color=blue][color=green]
> > the[color=darkred]
> > > > > > records
> > > > > > > > > based on the two criteria. The criteria used on the main[/color][/color]
> form[color=green][color=darkred]
> > > are
> > > > > > > values
> > > > > > > > > selected in two list boxes. When the user clicks on the[/color][/color]
> first[color=green][color=darkred]
> > > > list
> > > > > > box
> > > > > > > > > (lstCollege), it returns values in the second list box
> > > > (lstAcadPlan)
> > > > > > > based
> > > > > > > > > on the first. The user then clicks on the cmdShowResults[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> > > > filter
> > > > > > and
> > > > > > > > > return records in the datasheet subform. This works fine[/color]
> > except[color=darkred]
> > > > for
> > > > > > one
> > > > > > > > > problem. Both list boxes are set up for single select[/color]
> > values--I[color=darkred]
> > > > now
> > > > > > > need
> > > > > > > > to
> > > > > > > > > make the second list box (lstAcadPlan) a multi-select list[/color][/color]
> box[color=green][color=darkred]
> > > and
> > > > > > pass
> > > > > > > > the
> > > > > > > > > values to the filter. I have no idea how to include that[/color][/color][/color]
in[color=blue][color=green]
> > my[color=darkred]
> > > > code
> > > > > > and
> > > > > > > > was
> > > > > > > > > wondering if anyone had any ideas on what I should do.[/color][/color][/color]
Here[color=blue][color=green]
> > is[color=darkred]
> > > > the
> > > > > > code
> > > > > > > I
> > > > > > > > > have so far that works fine as long as only one value is
> > > selected
> > > > in
> > > > > > the
> > > > > > > > > second list box:
> > > > > > > > >
> > > > > > > > > Private Sub cmdShowResults_Click()
> > > > > > > > > Me.sfrmSearchResults.Visible = True
> > > > > > > > > Me.lblSubformInstructions.Visible = True
> > > > > > > > > Dim strWhere As String
> > > > > > > > > Dim rst As Recordset
> > > > > > > > >
> > > > > > > > > If Len(Me.lstCollege & "") > 0 Then
> > > > > > > > > strWhere = "[College] = '" & Me.lstCollege & "'"
> > > > > > > > > End If
> > > > > > > > >
> > > > > > > > > If Len(Me.lstAcadPlan & "") > 0 Then
> > > > > > > > > If Len(strWhere) > 0 Then
> > > > > > > > > strWhere = strWhere & "And [AcadPlan] = '" &
> > > > > > Me.lstAcadPlan
> > > > > > > &
> > > > > > > > > "'"
> > > > > > > > > Else
> > > > > > > > > strWhere = "[AcadPlan] = '" & Me.lstAcadPlan &[/color][/color]
> "'"[color=green][color=darkred]
> > > > > > > > > End If
> > > > > > > > > End If
> > > > > > > > > Forms(Me.Name)("sfrmSearchResults").Form.Filter =[/color]
> > strWhere[color=darkred]
> > > > > > > > > Forms(Me.Name)("sfrmSearchResults").Form.FilterOn =[/color][/color]
> True[color=green][color=darkred]
> > > > > > > > > End Sub
> > > > > > > > >
> > > > > > > > > Thank you,
> > > > > > > > >
> > > > > > > > > William
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]