Hi Graham,
Hope this is what you looking for...
Let assume the Field name for the datathat you wish to serch in database is "EmployeeName".
So the coding will be...
If you don't want the duplicate record being selected than you need to change the SQL statement to below:Code:Option Explicit Dim xDb As DAO.Database Dim xRs As DAO.Recordset Dim xData As String Dim xSQL As String Private Sub Form_Load() Set xDb = DBEngine.OpenDatabase(App.Path & "\db1.mdb", False, False) xData = InputBox("Enter A Name To Search For", "NAME SEARCH", "") If xData = "" Then Exit Sub xSQL = "SELECT * FROM TblEmployee WHERE EmployeeName LIKE '*" & xData & "*';" Set xRs = xDb.OpenRecordset(xSQL, dbOpenSnapshot) With xRs If .RecordCount <> 0 Then While Not .EOF Debug.Print .Fields(0) .MoveNext Wend End If End With xRs.Close xDb.Close Set xRs = Nothing Set xDb = Nothing End Sub
Good LuckCode:xSQL = "SELECT DISTINCT EmployeeName FROM TblEmployee WHERE EmployeeName LIKE '*" & xData & "*';"





Reply With Quote