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.