Search box keeps bringing up errors (1 Viewer)

anonymous user

New member
Local time
Today, 11:17
Joined
Nov 2, 2006
Messages
2
I'm trying to modify an existing database to make it easier and faster to search for homeowners. Currently, there is a search window that has two radio buttons, and a list box. one radio button is to search by address and another by last name. When you click one of these, it shows all the records in the list box. The problem is that 1. this is time consuming scrolling through over 300 records, and 2. more search options are needed, to include tag numbers of vehicles, and also phone numbers of residents. What Im trying to do is replace the radio buttons with a text box that will search all of the wanted fields, and produce a list of results in the list box. I'd rather not use a search button and just have the list box filter out as you type, but if a button must be used then thats fine. I've tried different ways, and searched all over the new for weeks, but cannot find the solution to my problem. Here is the current and original code. Thanks in advance for your help....Mike

Type of Search = Radio Buttons
By Search Type = List Box
HOMEOWNERS = table where all the info is located
GET = cmd button to open form with results selected in list box

---------
Private Sub Option35_GotFocus()

End Sub

Private Sub Option37_GotFocus()

End Sub


Private Sub Type_of_Search_AfterUpdate()
With CodeContextObject
If .[Type of Search] = 1 Then
.[By Search Type].RowSource = ""
.[Search Text].Caption = "Select the Last Name to Search for"
.[By Search Type].ColumnCount = 3
.[By Search Type].ColumnWidths = "1.5 in;1 in;0 in"
.[By Search Type].BoundColumn = 3
.[By Search Type].RowSource = "SELECT DISTINCTROW HOMEOWNERS.LastName, HOMEOWNERS.FirstName, HOMEOWNERS.Address FROM HOMEOWNERS WHERE ((Not (HOMEOWNERS.LastName) Is Null)) ORDER BY HOMEOWNERS.LastName, HOMEOWNERS.Address;"
ElseIf .[Type of Search] = 2 Then
.[By Search Type].RowSource = ""
.[Search Text].Caption = "Select the Address to Search for"
.[By Search Type].ColumnCount = 2
.[By Search Type].ColumnWidths = "1.5 in;1 in"
.[By Search Type].BoundColumn = 1
.[By Search Type].RowSource = "SELECT HOMEOWNERS.Address, HOMEOWNERS.LastName FROM HOMEOWNERS WHERE ((Not (HOMEOWNERS.Address) Is Null)) ORDER BY HOMEOWNERS.Address;"
End If
End With
End Sub
Private Sub Get_Click()
On Error GoTo Get_Click_Err
Dim Criteria As String
Dim MyRS As DAO.Recordset

Set MyRS = Forms![BASIC DATA].RecordsetClone
Criteria = "[Address] = """ & Me![By Search Type] & """"
MyRS.FindFirst Criteria
If Not MyRS.NoMatch Then
Forms![BASIC DATA].Bookmark = MyRS.Bookmark
End If
MyRS.close
Set MyRS = Nothing

DoCmd.close acForm, "Homeowners Search Dialog"

Get_Click_Exit:
Exit Sub

Get_Click_Err:
MsgBox Err.Description
Resume Get_Click_Exit

End Sub
Private Sub close_button_Click()
On Error GoTo Err_close_button_Click


DoCmd.close

Exit_close_button_Click:
Exit Sub

Err_close_button_Click:
MsgBox Err.Description
Resume Exit_close_button_Click

End Sub
Private Sub close_Click()
On Error GoTo Err_close_Click


DoCmd.close

Exit_close_Click:
Exit Sub

Err_close_Click:
MsgBox Err.Description
Resume Exit_close_Click

End Sub
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 16:17
Joined
Sep 12, 2006
Messages
15,640
try docmd.findrecord - you can take a single search string (therefore address or name) and search records in a variety of ways to find what you are after. I tend to use a findfirst, and a findnext button, as one of the options is search the datset from the top, or continuing down the file.

This will automatically place you in the correct record., with hardly any code
 

Users who are viewing this thread

Top Bottom