G
G
I have a buildcriteria function on a search button
when I run it, it errors out on the first if-then statement. The error
message says I can't reference a property or method for a control unless the
control has the focus.
Do I have to .setfocus for each control? If so, it will go through all the
controls, causing bad flickering.
G
'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
'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 sql statement to the variable
Me.txtSql.SetFocus
Me.txtSql = sSql & sWhereClause
Me.cmdSearch.SetFocus
when I run it, it errors out on the first if-then statement. The error
message says I can't reference a property or method for a control unless the
control has the focus.
Do I have to .setfocus for each control? If so, it will go through all the
controls, causing bad flickering.
G
'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
'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 sql statement to the variable
Me.txtSql.SetFocus
Me.txtSql = sSql & sWhereClause
Me.cmdSearch.SetFocus