G
Guest
I have a form with 75 fields for the user to input/select search criteria.
I went into the help and pulled up a sample from the Northwind database, did
the sample and it worked great.
When I put it into my form, it does not construct the entire statement. It
only gives me "select * from data Where ". Any help on this would be greatly
appreciated.
Below is my code. I am only putting data in one text box, then clicking
"search button". I also need to know if I have the correct syntax for a
combobox and checkbox.
Private Sub cmdSearch_Click()
On Error Resume Next
Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
'Initialize the Where Clause variable.
sWhereClause = " Where "
'Start the first part of the select statement.
sSQL = "select * from data "
'Loop through each control on the form to get its value.
For Each ctl In Me.Controls
With ctl
'The only Control you are using is the text box.
'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
'Case acComboBox
'.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(.Lname, dbTEXT, .Value)
'End If
'Case acCheckBox
'.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 the forms recordsource equal to the new 'select statement.
Me.txtSql = sSQL & sWhereClause
Me.RecordSource = sSQL & sWhereClause
Me.Requery
End Sub
I went into the help and pulled up a sample from the Northwind database, did
the sample and it worked great.
When I put it into my form, it does not construct the entire statement. It
only gives me "select * from data Where ". Any help on this would be greatly
appreciated.
Below is my code. I am only putting data in one text box, then clicking
"search button". I also need to know if I have the correct syntax for a
combobox and checkbox.
Private Sub cmdSearch_Click()
On Error Resume Next
Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
'Initialize the Where Clause variable.
sWhereClause = " Where "
'Start the first part of the select statement.
sSQL = "select * from data "
'Loop through each control on the form to get its value.
For Each ctl In Me.Controls
With ctl
'The only Control you are using is the text box.
'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
'Case acComboBox
'.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(.Lname, dbTEXT, .Value)
'End If
'Case acCheckBox
'.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 the forms recordsource equal to the new 'select statement.
Me.txtSql = sSQL & sWhereClause
Me.RecordSource = sSQL & sWhereClause
Me.Requery
End Sub