Function GetQueryText() As String
Const BASE_SQL as string = _
"SELECT * " & _
"FROM Table "
Dim Where As String
[COLOR="Green"] 'construct a where clause using two fields on a form[/COLOR]
If Not IsNull(Me.Text0) Then Where = "And Field1 = " & Me.Text0
If Not IsNull(Me.Text2) Then Where = Where & "And Field2 = " & Me.Text2
If Where <> "" Then Where = "WHERE " & Mid(Where, 5)
[COLOR="Green"]'construct and return the whole SQL[/COLOR]
GetQueryText = BASE_SQL & Where
End Function