Chris
May 25th, 2000, 04:18 PM
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...
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
If you don't want the duplicate record being selected than you need to change the SQL statement to below:
xSQL = "SELECT DISTINCT EmployeeName FROM TblEmployee WHERE EmployeeName LIKE '*" & xData & "*';"
Good Luck :)
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...
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
If you don't want the duplicate record being selected than you need to change the SQL statement to below:
xSQL = "SELECT DISTINCT EmployeeName FROM TblEmployee WHERE EmployeeName LIKE '*" & xData & "*';"
Good Luck :)