dbTalk Databases Forums  

Multiple Field Search

comp.database.ms-access comp.database.ms-access


Discuss Multiple Field Search in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pragati
 
Posts: n/a

Default Multiple Field Search - 12-27-2003 , 05:12 AM






Hi !
Im developing a contact management software in accesss 2000.
I have been trying this for long but no success. I want to extract
records from a table that satisfy all the conditions specified by the
user. i have a form that provides interface to the user for specifying
his search conditions. (in the form of text boxes and combo boxes).
the user may select enter conditions in all text/combo boxes or he
might specify conditions in only a few of them. All the conditions
that the user specifies should be combined in a query and the
text/combo boxes that he leaves should not be combined in query.
how to display the resulting records in another form/report?

how can this be accomplished? using recordsets?
the whole project is complete except this .....

please help.

thanks in advance,
pragati

Reply With Quote
  #2  
Old   
Scott McDaniel
 
Posts: n/a

Default Re: Multiple Field Search - 12-28-2003 , 09:31 AM






You would iterate through the various controls on your form, determine if
there is a value entered, and build a valid Where clause. For example, if
you have a control named ctlFirstName then you'd do something like this:

Function GetWhereClause as String

Dim strWhere As String

If len(ctlFirstName) > 0 Then
If Len(strWhere) = 0 Then
strWhere = " strFirstName='" & Me.ctlFirstName & "'"
Else
strWhere = " AND strFirstName='" & Me.ctlFirstName & "'"
End If
End If

End Function

You'll have to go through each control and check for a value there ... if
there is a value in the control then add it to your Where clause. After
iterating through all controls, then build you SQL and attach the Where
clause

strSQL = "SELECT * FROM YourTable " & strWhere

You'll use this strSQL string to open your recordset. Note that this is VERY
simplistic .... it doesn't take into account the need to exlude records, the
need to use OR in your Where clause, or the need to use LIKE in your results
(i.e. LIKE '*sco*') ... these would take a lot more code to setup.

--
Scott McDaniel
CS Computer Software
www.thedatabaseplace.net

"Pragati" <pragatisagar (AT) yahoo (DOT) com> wrote

Quote:
Hi !
Im developing a contact management software in accesss 2000.
I have been trying this for long but no success. I want to extract
records from a table that satisfy all the conditions specified by the
user. i have a form that provides interface to the user for specifying
his search conditions. (in the form of text boxes and combo boxes).
the user may select enter conditions in all text/combo boxes or he
might specify conditions in only a few of them. All the conditions
that the user specifies should be combined in a query and the
text/combo boxes that he leaves should not be combined in query.
how to display the resulting records in another form/report?

how can this be accomplished? using recordsets?
the whole project is complete except this .....

please help.

thanks in advance,
pragati



Reply With Quote
  #3  
Old   
Pragati
 
Posts: n/a

Default Re: Multiple Field Search - 12-29-2003 , 02:49 AM



Thanks a ton!
I could get that through. My SQL query is ready now... just the way i
wanted.

but am stuck up in creating a recordset now.
how should one connect to database? use adodb or dao connection? are
there any particular setting reqd in vb editor?
what shud be the syntax for opening the above query in a recordset?

also ... can i pass a recordset variable to another form or report?
can a recordset created in one form be accessed in some other
form/report?

please help ....
thanks again
pragati

pragatisagar (AT) yahoo (DOT) com (Pragati) wrote in message news:<6d362a2f.0312270312.47776454 (AT) posting (DOT) google.com>...
Quote:
Hi !
Im developing a contact management software in accesss 2000.
I have been trying this for long but no success. I want to extract
records from a table that satisfy all the conditions specified by the
user. i have a form that provides interface to the user for specifying
his search conditions. (in the form of text boxes and combo boxes).
the user may select enter conditions in all text/combo boxes or he
might specify conditions in only a few of them. All the conditions
that the user specifies should be combined in a query and the
text/combo boxes that he leaves should not be combined in query.
how to display the resulting records in another form/report?

how can this be accomplished? using recordsets?
the whole project is complete except this .....

please help.

thanks in advance,
pragati

Reply With Quote
  #4  
Old   
Scott McDaniel
 
Posts: n/a

Default Re: Multiple Field Search - 12-29-2003 , 11:50 AM



In Access 2000, DAO would be the fastest way:

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset(YourSQL)

Note there may be some other paramaters you can set ...

You can pass a recordset variable to another form or report, but it's often
easier to set the RecordSource of the form or report to your valid SQL
string:

Forms!NameOfYourForm.Recordsource = YourSQL

Reports are different ... you can't set the recordsource once the report has
opened, but you can run code in the Activate event that "looks" at an open
form and pulls the .Recordsource from there.

"Pragati" <pragatisagar (AT) yahoo (DOT) com> wrote

Quote:
Thanks a ton!
I could get that through. My SQL query is ready now... just the way i
wanted.

but am stuck up in creating a recordset now.
how should one connect to database? use adodb or dao connection? are
there any particular setting reqd in vb editor?
what shud be the syntax for opening the above query in a recordset?

also ... can i pass a recordset variable to another form or report?
can a recordset created in one form be accessed in some other
form/report?

please help ....
thanks again
pragati

pragatisagar (AT) yahoo (DOT) com (Pragati) wrote in message
news:<6d362a2f.0312270312.47776454 (AT) posting (DOT) google.com>...
Hi !
Im developing a contact management software in accesss 2000.
I have been trying this for long but no success. I want to extract
records from a table that satisfy all the conditions specified by the
user. i have a form that provides interface to the user for specifying
his search conditions. (in the form of text boxes and combo boxes).
the user may select enter conditions in all text/combo boxes or he
might specify conditions in only a few of them. All the conditions
that the user specifies should be combined in a query and the
text/combo boxes that he leaves should not be combined in query.
how to display the resulting records in another form/report?

how can this be accomplished? using recordsets?
the whole project is complete except this .....

please help.

thanks in advance,
pragati



Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.