View Full Version : Search based on a form


Niswaar
08-03-2008, 01:58 AM
hi, i have searched the whole forum and couldnt just meet the situation hindered by me.

heres the issue............

Form: Client ID (300+ records)
Fields: File_ID, Last Name, Date of Birth

Form: Search
Fields: File_ID
I would like to search "Client ID" records FROM THIS FORM based on "File_ID"

here's what im using



Private Sub Search_Click()

Dim strWhere As String
Dim strError As String

strWhere = "1=1"

' If File_ID
If Nz(Me.File_ID) <> "" Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "Client_ID.File_ID Like '*" & Me.File_ID & "*'"
End If

If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Results", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Results.Form.Filter = strWhere
Me.Results.Form.FilterOn = True
End If
End Sub



Now, after clicking the search button, it asks me for "Enter Parameter Value" and further DOESNT filter the results...

Any help would be kindly appreciated.

Thanks in advance

DCrake
08-03-2008, 11:28 PM
If you only have 300 or so clients it may be a simpler way to insert a combo box into your form header section that contains a list of all the client ID's sorted A-Z.

You user then types in the id into the combobox (have autofill switched on), then on the after update of the combo box set the form filter to equal the id the user selected.

The code you are using seems a bit fragmented and illogical.

Could not understand what the strWhere = "1=1" relates to.

Also if your id field is a numeric/autonumber field the Like operatordoes not match the datatype. Like operators are usually employed around string fields.

CodeMaster::cool:

neileg
08-04-2008, 12:23 AM
Why not use the FileID as a parameter for a select query?