Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2007

Tip: Looking for answers? Try searching our database.

Form dependent queries with multiple criteria options

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Prohock - 05 Nov 2007 04:21 GMT
Is it possible to do the following in MS Access and if it is please outline
the conceptual idea of what needs to be done?

I would like the user to open a form [SearchForm] and enter a ID number
(primary key), or a last name, or a first name in a textbox named
[SearchCriteria] located on that form. After hitting a submit button
[SearchButton], all records that contain i.e. the same first name would be
displayed in a subform or if the use choose to enter a last name, then all
records that contain the identified last name would be displayed. The user
would some how select the desired record from the list and a report on the
selected record would be generated.

This seems to be a logical approach to a simple problem, however I am only
finding bits and pieces for a solution in the discussion groups and I can't
seem to put it all together.
Allen Browne - 05 Nov 2007 05:32 GMT
If you just want to search on one field (but be able to choose which one),
you can implement this with copy'n'paste (i.e. without having to write any
new code):
   Find as you type - Filter forms with each keystroke
at:
   http://allenbrowne.com/AppFindAsUType.html

If you want to give the user the option to enter multiple criteria, this one
demonstrates how to write the filtering code for the specific fields you
need:
   Search form - Handle many optional criteria
at:
   http://allenbrowne.com/ser-62.html

Once you have the form filtered correctly, you can then use the form's
Filter in the WhereCondition of OpenReport. The "Trouble-shooting and
Extending" section in the last link above discusses that.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Is it possible to do the following in MS Access and if it is please
> outline
[quoted text clipped - 13 lines]
> can't
> seem to put it all together.
Prohock - 07 Nov 2007 07:01 GMT
Hi Allen

I have created a form that provides the parameter to the query that
functions very well, however this is what happens when I hit the submit
button on my form. After entering the search criteria in the form, and
hitting enter, the parameter value window opens and the words that are typed
in the form are displayed above the entry box in the parameter value pop up
window. If I enter the search criteria again in the parameter value box the
query runs perfect.

How can I prevent the parameter value window from opening and having to
enter the search criteria twice?

> If you just want to search on one field (but be able to choose which one),
> you can implement this with copy'n'paste (i.e. without having to write any
[quoted text clipped - 31 lines]
> > can't
> > seem to put it all together.
Allen Browne - 07 Nov 2007 10:27 GMT
Acces pops up the parameter window if it cannot resolve the name.

For example, you may have misspelled the name, or the form may not be open.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hi Allen
>
[quoted text clipped - 55 lines]
>> > can't
>> > seem to put it all together.
Prohock - 10 Nov 2007 18:05 GMT
Hi Allen

Thanks for helping me along the way, I feel that I am very close to working
this out.

Is it possible to have the user enter a first or last name in a single
unbound textbox on a form and run a query that will pull up all records
matching either the first or last name entered?

This is what I have so far, it only works when the last name is entered.

VBA

Private Sub cmdFilter_Click()
Dim strWhere As String
If Not IsNull(Me.txtFilterMainName) Then
       strWhere = Me.txtFilterMainName
       strWhere = "([FirstName] Like ""*" & Me.txtFilterMainName & "*"") or "
   End If
   
   If Not IsNull(Me.txtFilterMainName) Then
       strWhere = Me.txtFilterMainName
       strWhere = "([LastName] Like ""*" & Me.txtFilterMainName & "*"") "
   End If
       Me.Filter = strWhere
       Me.FilterOn = True
End Sub

query SQL
SELECT qryRecordSource.StudentID, qryRecordSource.FirstName,
qryRecordSource.LastName, qryRecordSource.CurrentGrade
FROM qryRecordSource
GROUP BY qryRecordSource.StudentID, qryRecordSource.FirstName,
qryRecordSource.LastName, qryRecordSource.CurrentGrade
HAVING (((qryRecordSource.FirstName) Like "*" &
Forms!StudentReport!txtFilterMainName & "*") Or ((qryRecordSource.LastName)
Like "*" & Forms!StudentReport!txtFilterMainName & "*"));

> Acces pops up the parameter window if it cannot resolve the name.
>
[quoted text clipped - 59 lines]
> >> > can't
> >> > seem to put it all together.
Prohock - 10 Nov 2007 18:49 GMT
Allen, Answered my own question: I used

VBA
strWhere = "[FirstName] Like '*" & Me.txtFilterMainName & "*' Or " &
"[LastName] Like '*" & Me.txtFilterMainName & "*'"

and I was able to join them together and everything works just fine.

Thanks Again

> Hi Allen
>
[quoted text clipped - 97 lines]
> > >> > can't
> > >> > seem to put it all together.
Allen Browne - 10 Nov 2007 22:25 GMT
Great! You have it all sorted out.

If you are interested in combining filters from several unbound text boxes,
you might enjoy this example:
   Search form - Handle many optional criteria
at:
   http://allenbrowne.com/ser-62.html

The sample database illustrates how to handle different field types, a date
range, etc.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Allen, Answered my own question: I used
>
[quoted text clipped - 132 lines]
>> > >> > can't
>> > >> > seem to put it all together.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.