Code:
Dim TableSource As String
' Tablename from which records are taken
Dim SearchField As String
' Field used in the "Where" clause
Dim SearchString As String
' Matching string used in the "Where" clause
Dim SearchValue As Integer
' For "Where" clause with numeric field.
' (Type may be other than Integer)
Dim SortField As String
' Field for sorting alpahbetically
Dim SQL As String
' This is where we'll put the SQL string
SQL = "Select * from [" & TableSource & "]" SQL = SQL & " Where [" & SearchField & "] Like ""*" & SearchString & "*""" SQL = SQL & " Order by [" & SortField & "]" Data1.RecordSource = SQL Data1.Refresh
where Data1 is a Form or Report object