Thank you so much both for your replies.I used both your advice and this is what I came up with.
Private Sub CmdSearch_Click_Click()
On Error Resume Next
Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
Dim objConn
'Initialize the Where Clause variable.
sWhereClause = " Where "
'Start the first part of the select statement.
sSQL = "select * from Customers "
'Loop through each control on the form to get its value.
For Each ctl In Me.Controls
With ctl
'The only Controls used here are text boxes.
'However, you can add as many types of controls as you want.
Select Case .ControlType
Case acTextBox
.SetFocus
'This is the function that actually builds
'the clause.
If sWhereClause = " Where " Then
sWhereClause = sWhereClause & BuildCriteria(.Name, dbText, .Text)
Else
sWhereClause = sWhereClause & " and " & BuildCriteria(.Name, dbText, .Text)
End If
End Select
End With
Next ctl
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.CommandTimeout = 0
objConn.ConnectionTimeout = 0
objConn.Open MM_DB2_STRING
Me.Results = sSQL & sWhereClause
Me.Results.Requery ' Results is the name of my list box
End Sub
But I still don't get anything in my list box when I use a
custId that I know for sure exists in my table.In my list
box property window I have Table/query for Row Source Type
and I have sSQL & sWhereClause for Row Source and Control
Source is blank.
Thanks again for your help