Solved

Filters

Posted on 1999-01-18
8
292 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

757 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

20 Experts available now in Live!

Get 1:1 Help Now