Searching using a drop down list

simontheak

New Member
Joined
Jan 21, 2003
Messages
5
At the moment I am able to allow a database to be searched by asking the user to type in a search term in a pop up window (like[?]).

I am wondering though whether it is possible for Access to display a drop down list so that the user can select one of the options to perform a search.

Is this possible?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
On 2003-01-22 05:36, simontheak wrote:
At the moment I am able to allow a database to be searched by asking the user to type in a search term in a pop up window (like[?]).

I am wondering though whether it is possible for Access to display a drop down list so that the user can select one of the options to perform a search.

Is this possible?

Hi again, this is possible and in fact theres a pre-built function to do it so its a breeze :)

Draw the combobox on your form and a wizard pops up with three options. Select the first one - "i want the combobox to lookup values in a table or query". Select the table or query that your form is based upon and the field you want to show the drop down on and your away. Post again if you have trouble.
 
Upvote 0
Sorry to bother you again.

I've created the drop down list on my form, and it's been populated by the names without a problem

The thing is that ideally I would like to run a Querie to search for the name I select in the box.

How would I go about doing that? I've been messing around with the OnChange event in the properties box, but can't find a way to run a Querie!
This message was edited by simontheak on 2003-01-22 06:12
 
Upvote 0
On 2003-01-22 06:08, simontheak wrote:
Sorry to bother you again.

I've created the drop down list on my form, and it's been populated by the names without a problem

The thing is that ideally I would like to run a Querie to search for the name I select in the box.

How would I go about doing that? I've been messing around with the OnChange event in the properties box, but can't find a way to run a Querie!
This message was edited by simontheak on 2003-01-22 06:12

No bother at all. If you cant ask a question here where can you? :)

The nature of the dropdown box you created ensures that it lists only valid entries anyway. If its not in the drop down list then it aint there.

However in saying that if you have a humungous list then it can be difficult at times to find an entry from the list. I havent tried to incorporate a search and a list box together but I have created my own custom search form.

Heres the code for the search where this code is linked to a command button called FindCodeNum, there is an unbound textbox called txtGotoRecord and the field to search for on is called ProjectNumber. Just change these to suit (use Edit-Replace)

Private Sub FindCodeNum_Click()
On Error GoTo Err_FindCodeNum_Click
Dim SearchBox

Me.Recalc

'Set focus to search box
Me.txtGotoRecord.SetFocus

'first check if a valid number was entered
If txtGotoRecord.Value = "" Or IsNumeric(txtGotoRecord.Value) = False Then
MsgBox "Please enter a number and try again", vbExclamation, "Code Number Required"
txtGotoRecord.Value = ""
txtGotoRecord.SetFocus
GoTo Exit_FindCodeNum_Click
End If

'Initialize values
SearchBox = Me.txtGotoRecord


'Set focus to the field in the form to search on
ProjectNumber.SetFocus

'Look for the number
DoCmd.FindRecord SearchBox, acEntire, False, acSearchAll, True, acCurrent, True

'Determine search result
ProjectNumber.SetFocus
If ProjectNumber.Value<> Val(SearchBox) Then
MsgBox "The Record you searched for was not found", vbInformation, "Project Record Not Found"
Me.txtGotoRecord.SetFocus
Exit Sub
End If

Exit_FindCodeNum_Click:
Exit Sub

Err_FindCodeNum_Click:
MsgBox Err.Description
Resume Exit_FindCodeNum_Click

End Sub

Note that I am looking for a number in this instance. If you are looking for text then it will need to be slightly different as you will probably be searching for parts of the field rather than an exact match. If you want to search for multiple things, like a number field or a name field you can use option buttons to select what to search for and amend the code a bit to cater for what option was selected.

Let me know what you are after.
 
Upvote 0

Forum statistics

Threads
1,221,507
Messages
6,160,219
Members
451,631
Latest member
coffiajoseph

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top