Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filters

Posted on 1999-01-18
8
Medium Priority
?
314 Views
Last Modified: 2012-05-04
I have a form in VB5 and I want to filter on 4 of the fields on the form could be all the 4 or only one of them. These fields read from a recordset so the final result when I browse through, iwill only see these filtered records.
thank you
0
Comment
Question by:abidr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 

Author Comment

by:abidr
ID: 1469227
Edited text of question
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 160 total points
ID: 1469228
Put a button on the form that triggers the lookup. When it does, simply build your query to match.

In this example a build a query based on the assumption that two fields are filled in. Then I test to see if one or the other field has been left blank and adjust my query accordingly. Finally I run the query and check to make sure that at least one record has been returned. My table is called RESULTS and there are at least two fields, CLIENT and DEBTOR. My form has a pair of text boxes CLIENT and DEBTOR. My database, DB, is already standing open.

SortKey = "select * from results where client like '" & client.Text & "*' or debtor=" & debtor.Text
If Len(debtor.Text) < 1 Then SortKey = "select * from results where client like '" & client.Text & "*'"
If Len(client.Text) < 1 Then SortKey = "select * from results where debtor=" & debtor.Text
'
Set rs = db.OpenRecordset(SortKey)
If rs.BOF And rs.EOF Then GoTo isempty

0
 

Author Comment

by:abidr
ID: 1469229
thanks,
As my knowledge is ltd, I can understand that the sql makes the filter, but how can I browse thru the filtered records of the results table or the query.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:mark2150
ID: 1469230
You can load them in a control or show them one at a time with an entry screen type of page. Simply copy the contents of each field into a TextBox's .Text property. Put a couple of buttons on the page, [Next] and [Prev]. Have them perform a .MoveNext and .MovePrev in the filtered data set and then call the sub to load the current record onto the screen. Be sure to check .EOF and .BOF prior to call to prevent "No Current Record" errors.

PRIVATE SUB Btn_Next_Click()
rs.MoveNext
if rs.EOF then
  call clearpage
  Btn_Next.Enabled = False
else
  call showrecord
endif
END SUB

PRIVATE SUB Btn_Prev_Click()
rs.MovePrev
if rs.EOF then
  call clearpage
  Btn_Prev.Enabled = False
else
  call showrecord
endif
END SUB

PRIVATE SUB ShowRecord()
for ndx = 1 to Text1.Ubound
  Text1(ndx).Text = ""
next ndx
'
text1(1).Text = rs![field 1]
.

END SUB

M

0
 

Author Comment

by:abidr
ID: 1469231
Thanks,
I managed to filter & view records, but if I want to make a new search, I need to cancel the first filter and how can I cancel the first filter before performing another from the same table.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1469232
All you do is do a RS.CLOSE to shut down the first query and then re-run the OPENRECORDSET with the new params.

M

0
 

Author Comment

by:abidr
ID: 1469233
thanks  a lot, I have more of these.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1469234
No problem. Write me direct at:

mark_lambert@ntsc.navy.mil

M

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question