Question : VB me.controls function

I have in code right now as attached to build a dynamic SQL statement. I need to however place a "(" before the first statement and a ")" after the last statement added. Is there a way to say after "for each ctrol in me.controls" for the first ctrl add this "(" and for the last ctrol add this ")" ??

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Dim ctrl As Control
Dim ssql As String
Dim sWhereClause As String
Dim projyear As String


sWhereClause = "Where "
ssql = "SELECT *  From qryprojectyear "

For Each ctrl In Me.Controls
    If TypeName(ctrl) = "CheckBox" Then
        If ctrl.Name <> "all" Then
            If ctrl = True Then
                Me.ActiveControl.SetFocus
                If sWhereClause = "Where " Then
                   sWhereClause = sWhereClause & BuildCriteria("Project_Scope", dbText, ctrl.Name)
                Else
                   sWhereClause = sWhereClause & " or " & BuildCriteria("Project_Scope", dbText, ctrl.Name)
                End If
            End If
        End If
    End If
    
Next ctrl

Answer : VB me.controls function

And is evaluated before Or so

Where "Project_scope = "LPA" or Project_scope="REG" and Year= 2008 and Month = January"

is equivalent to

Where "Project_scope = "LPA" or (Project_scope="REG" and Year= 2008 and Month = January)"

Part of your problem is double quotation marks within double quotation marks. Try instead:

Where "Project_scope = 'LPA' or Project_scope='REG' and Year= 2008 and Month = 'January'"


Operator precedence (from VBA help):
When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence.

When expressions contain operators from more than one category, arithmetic operators are evaluated first, comparison operators are evaluated next, and logical operators are evaluated last. Comparison operators all have equal precedence; that is, they are evaluated in the left-to-right order in which they appear. Arithmetic and logical operators are evaluated in the following order of precedence:

Arithmetic                                     Comparison                                 Logical
Exponentiation (^)                       Equality (=)                                 Not
Negation (–)                                 Inequality (<>)                           And
Multiplication and division (*, /)    Less than (<)                             Or
Integer division (\)                       Greater than (>)                         Xor
Modulus arithmetic (Mod)             Less than or equal to (<=)         Eqv
Addition and subtraction (+, –)    Greater than or equal to (>=)     Imp
String concatenation (&)              Like
                                                    Is  


When multiplication and division occur together in an expression, each operation is evaluated as it occurs from left to right. When addition and subtraction occur together in an expression, each operation is evaluated in order of appearance from left to right. Parentheses can be used to override the order of precedence and force some parts of an expression to be evaluated before others. Operations within parentheses are always performed before those outside. Within parentheses, however, operator precedence is maintained.

The string concatenation operator (&) is not an arithmetic operator, but in precedence, it does follow all arithmetic operators and precede all comparison operators.

The Like operator is equal in precedence to all comparison operators, but is actually a pattern-matching operator.

The Is operator is an object reference comparison operator. It does not compare objects or their values; it checks only to determine if two object references refer to the same object.



Basic string theory:

Think of strings like quotes in a fictional book.
Bob said, "Dave died" and then he said "I am quite unhappy about it."
is quite different than
Bob said, "Dave died and then he said I am quite unhappy about it."
which would be improbable except in a ghost story.
Apostrophes can be used just like quotation marks to identify a string so "This is confusing!!"  =   'This is confusing!!'
This is done so you can put a string in a string just like in fictional books:
Bob said, "Dave died and then he said 'I am quite unhappy about it.'"
A little different than Bob said, "Dave died and then he said I am quite unhappy about it." but still improbable.

The ampersand puts two strings together:
"I am string one" & "and I am string two" becomes "I am string oneand I am string two"
since computers are dumb and don't know to put an extra space between the two strings, you would do this:
"I am string one" & " " & "and I am string two" becomes "I am string one and I am string two"
or
"I am string one" & " and I am string two" becomes "I am string one and I am string two"


By placing the ampersand inside the quotation marks in "&ID&", you get a string with ampersand, eye, dee, ampersand.  Probably not what you want.  The ampersand should be outside of the string to put two strings together.

For SQL, the semicolon should be at the end:
strSQL = "Update Micro_Master_Log Set Path_Status ='" & ComboCfuTransfer & "' Where ID=" & Log & ";"
assuming the field you want to look up is "ID" and the control that has the ID data is "Log"  

Let's assume ComboCfuTransfer = "Hello Dolly!"  and Log = 23 then when the line
strSQL = "Update Micro_Master_Log Set Path_Status ='" & ComboCfuTransfer & "' Where ID= " & Log & ";"
is put together with the ampersands, it becomes
strSQL = "Update Micro_Master_Log Set Path_Status ='Hello Dolly!' Where ID= 23;"
Random Solutions  
 
programming4us programming4us