Hello All,
An unbound search form searches up to 5 separate criteria for selected table or query by using criteria enclosed in asterisks - *criteria*
How can code be changed so criteria can be entered without being enclosed in asterisks?
From sections below, not sure how to edit syntax for
1. strSQL = "Select * "
2. "Select * from [" & Me.lstTables.Column(0) & "] Where 1=2", dbOpenSnapshot)
3. strWhere = strWhere & strJoinType & "[" & Me("cbxFld" & i) & "] like '*'"
Sub sBuildSQL()
' Take what's currently selected on the form
' and create a dynamic SQL statement for the
' lstResults listbox.
'
On Error GoTo ErrHandler
Dim strSQL As String
Dim strWhere As String
Dim strJoinType As String
Dim i As Integer
Dim j As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim tdf As TableDef
Dim qdf As DAO.QueryDef
Dim rsQdf As DAO.Recordset
Dim fld As DAO.Field
Const conMAXCONTROLS = 5
Set db = DBEngine(0)(0)
strSQL = "Select * "
...
'Get the a reference to the field in the table/Query as
'we'll need it for BuildCriteria later on
If Me.lstTables.Column(1) = "Table" Then
Set tdf = db.TableDefs(Me.lstTables.Column(0))
Set fld = tdf.Fields(Me("cbxFld" & i))
Else
Set rsQdf = db.OpenRecordset( _
"Select * from [" & Me.lstTables.Column(0) & "] Where 1=2", dbOpenSnapshot)
Set fld = rsQdf.Fields(Me("cbxFld" & i))
End If
'Only build a criteria if something's typed in the textbox
'otherwise assume all records
If Not IsNull(Me("txtVal" & i)) Then
strWhere = strWhere & strJoinType & Application.BuildCriteria( _
"[" & Me("cbxFld" & i) & "]", _
fld.Type, Me("txtVal" & i) & "")
Else
strWhere = strWhere & strJoinType & "[" & Me("cbxFld" & i) & "] like '*'"
End If
End If
Next
'The final all important SQL statement
strSQL = strSQL & " from [" & Me.lstTables & "] Where " & strWhere
'If the user has modified the SQL directly, take what they've typed in
If Nz(Me.chkEditSQL, False) = False Then
'"save" it in the textbox
Me.txtSQL = strSQL
End If
...
An unbound search form searches up to 5 separate criteria for selected table or query by using criteria enclosed in asterisks - *criteria*
How can code be changed so criteria can be entered without being enclosed in asterisks?
From sections below, not sure how to edit syntax for
1. strSQL = "Select * "
2. "Select * from [" & Me.lstTables.Column(0) & "] Where 1=2", dbOpenSnapshot)
3. strWhere = strWhere & strJoinType & "[" & Me("cbxFld" & i) & "] like '*'"
Sub sBuildSQL()
' Take what's currently selected on the form
' and create a dynamic SQL statement for the
' lstResults listbox.
'
On Error GoTo ErrHandler
Dim strSQL As String
Dim strWhere As String
Dim strJoinType As String
Dim i As Integer
Dim j As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim tdf As TableDef
Dim qdf As DAO.QueryDef
Dim rsQdf As DAO.Recordset
Dim fld As DAO.Field
Const conMAXCONTROLS = 5
Set db = DBEngine(0)(0)
strSQL = "Select * "
...
'Get the a reference to the field in the table/Query as
'we'll need it for BuildCriteria later on
If Me.lstTables.Column(1) = "Table" Then
Set tdf = db.TableDefs(Me.lstTables.Column(0))
Set fld = tdf.Fields(Me("cbxFld" & i))
Else
Set rsQdf = db.OpenRecordset( _
"Select * from [" & Me.lstTables.Column(0) & "] Where 1=2", dbOpenSnapshot)
Set fld = rsQdf.Fields(Me("cbxFld" & i))
End If
'Only build a criteria if something's typed in the textbox
'otherwise assume all records
If Not IsNull(Me("txtVal" & i)) Then
strWhere = strWhere & strJoinType & Application.BuildCriteria( _
"[" & Me("cbxFld" & i) & "]", _
fld.Type, Me("txtVal" & i) & "")
Else
strWhere = strWhere & strJoinType & "[" & Me("cbxFld" & i) & "] like '*'"
End If
End If
Next
'The final all important SQL statement
strSQL = strSQL & " from [" & Me.lstTables & "] Where " & strWhere
'If the user has modified the SQL directly, take what they've typed in
If Nz(Me.chkEditSQL, False) = False Then
'"save" it in the textbox
Me.txtSQL = strSQL
End If
...