Solved

Filters

Posted on 1999-01-18
8
297 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
  • 4
  • 4
8 Comments
 

Author Comment

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

Accepted Solution

by:
mark2150 earned 40 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

809 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