PC Review


Reply
Thread Tools Rate Thread

Creating a filter using VBA

 
 
David
Guest
Posts: n/a
 
      2nd Sep 2009
Hello

I'm trying to filter data in a form (It does not have a Subform) based on
what what user types in two unbound text boxs. I am able to do this based of
one but I want to filter for 2, so that where my problem lies.

Here is what I been playing around with, but it does not work. It will
filter for the first textbox then clear the filter and filter for the next
textbox.

Private Sub Command27_Click()
If IsNull(Me.FilterLName) Then
MsgBox "Please Enter Student's Last Name"
FilterLName.SetFocus

Else
Me.Filter = "Lname = """ & Me.FilterLName & """"
Me.FilterOn = True
Me.Filter = "Fname = """ & Me.FilterLName & """"
Me.FilterOn = True
End If

End Sub

Any help would be great, thank you
 
Reply With Quote
 
 
 
 
golfinray
Guest
Posts: n/a
 
      2nd Sep 2009
I think it is easier using cascading combo boxes. Check Marting Greene at
www.fontstuff.com or Allen Browne at www.allenbrowne for excellent examples.
--
Milton Purdy
ACCESS
State of Arkansas


"David" wrote:

> Hello
>
> I'm trying to filter data in a form (It does not have a Subform) based on
> what what user types in two unbound text boxs. I am able to do this based of
> one but I want to filter for 2, so that where my problem lies.
>
> Here is what I been playing around with, but it does not work. It will
> filter for the first textbox then clear the filter and filter for the next
> textbox.
>
> Private Sub Command27_Click()
> If IsNull(Me.FilterLName) Then
> MsgBox "Please Enter Student's Last Name"
> FilterLName.SetFocus
>
> Else
> Me.Filter = "Lname = """ & Me.FilterLName & """"
> Me.FilterOn = True
> Me.Filter = "Fname = """ & Me.FilterLName & """"
> Me.FilterOn = True
> End If
>
> End Sub
>
> Any help would be great, thank you

 
Reply With Quote
 
Krzysztof Naworyta
Guest
Posts: n/a
 
      2nd Sep 2009
David wrote:


(...)
| Else
| Me.Filter = "Lname = """ & Me.FilterLName & """ AND Fname = """
& Me.FilterLName & """"
| Me.FilterOn = True
| End If


--
KN

 
Reply With Quote
 
David
Guest
Posts: n/a
 
      2nd Sep 2009
With the amount of data(16000 records) I think it will be easier to filter
using textboxes. Is there way to use an & to combine these two lines of
code. I am really bad at figuring out how to use the &.

Thanks

"golfinray" wrote:

> I think it is easier using cascading combo boxes. Check Marting Greene at
> www.fontstuff.com or Allen Browne at www.allenbrowne for excellent examples.
> --
> Milton Purdy
> ACCESS
> State of Arkansas
>
>
> "David" wrote:
>
> > Hello
> >
> > I'm trying to filter data in a form (It does not have a Subform) based on
> > what what user types in two unbound text boxs. I am able to do this based of
> > one but I want to filter for 2, so that where my problem lies.
> >
> > Here is what I been playing around with, but it does not work. It will
> > filter for the first textbox then clear the filter and filter for the next
> > textbox.
> >
> > Private Sub Command27_Click()
> > If IsNull(Me.FilterLName) Then
> > MsgBox "Please Enter Student's Last Name"
> > FilterLName.SetFocus
> >
> > Else
> > Me.Filter = "Lname = """ & Me.FilterLName & """"
> > Me.FilterOn = True
> > Me.Filter = "Fname = """ & Me.FilterLName & """"
> > Me.FilterOn = True
> > End If
> >
> > End Sub
> >
> > Any help would be great, thank you

 
Reply With Quote
 
David
Guest
Posts: n/a
 
      2nd Sep 2009
Prefect, thank you very much!

"Krzysztof Naworyta" wrote:

> David wrote:
>
>
> (...)
> | Else
> | Me.Filter = "Lname = """ & Me.FilterLName & """ AND Fname = """
> & Me.FilterLName & """"
> | Me.FilterOn = True
> | End If
>
>
> --
> KN
>
>

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      2nd Sep 2009
David wrote:
>I'm trying to filter data in a form (It does not have a Subform) based on
>what what user types in two unbound text boxs. I am able to do this based of
>one but I want to filter for 2, so that where my problem lies.
>
>Here is what I been playing around with, but it does not work. It will
>filter for the first textbox then clear the filter and filter for the next
>textbox.
>
>Private Sub Command27_Click()
>If IsNull(Me.FilterLName) Then
> MsgBox "Please Enter Student's Last Name"
> FilterLName.SetFocus
>
>Else
> Me.Filter = "Lname = """ & Me.FilterLName & """"
> Me.FilterOn = True
> Me.Filter = "Fname = """ & Me.FilterLName & """"
> Me.FilterOn = True
>End If



Not sure what you are doing with FName, but try something
like:

Private Sub Command27_Click()
Dim strFltr As String
If IsNull(Me.FilterLName) Then
MsgBox "Please Enter Student's Last Name"
FilterLName.SetFocus
Exit Sub
Else
strFltr = strFltr & " AND Lname = """ & Me.FilterLName &
""""
End If

If IsNull(Me.FilterFName) Then
MsgBox "Please Enter Student's First Name"
FilterFName.SetFocus
Exit Sub
Else
strFltr = strFltr & " AND Fname = """ & Me.FilterFName &
""""
End If

Me.Filter = Mid(strFltr, 6)
Me.FilterOn = True

End Sub

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a filter form solitudebytheshore Microsoft Access Forms 1 21st Sep 2008 12:01 PM
Creating a spreadsheet that will filter =?Utf-8?B?TGlqdSBHZW9yZ2U=?= Microsoft Excel New Users 2 10th Jul 2006 09:26 PM
Creating a 4-step filter =?Utf-8?B?QXVudHNhbGx5?= Microsoft Excel Misc 5 26th May 2006 10:31 PM
Trouble creating a filter =?Utf-8?B?ZGVmYXVsdDEwNQ==?= Microsoft Access Queries 1 27th Nov 2005 05:10 PM
Need help creating FILTER Beema Microsoft Excel Worksheet Functions 7 29th Jun 2004 05:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:47 PM.