Solved

Filters

Posted on 1999-01-18
8
294 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now