operator as a variable (syntax ?)

M

Mark Kubicki

i'm having syntax problems setting an operator as a variable... any
suggestions would be greatl;y appreciated

If strFileType = ... Then
strCriteria = "<> "
Else
strCriteria = "="
End If

' Loop through all tables in the database.
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
If Left(tdf.Name, 3) & strCriteria & "tbe" Then
...


thanks in advance,
mark
 
T

tina

well, the problem is you're passing a string value, so your expression comes
out as a string, as

"the value of Left(tdf.Name, 3)=tbe"

a string won't run by itself - it's just a string; but it might work in the
Eval() function, as

If strFileType = ... Then
strCriteria = " <> "
Else
strCriteria = " = "
End If
If Eval(Left(tdf.Name, 3) & strCriteria & "tbe")

i'm assuming that you're replacing the ... in the above code with an actual
string value. recommend you read up on the Eval() function in VBA Help. if
the Eval() function doesn't do it, you can always include the logic in your
loop, as

' Loop through all tables in the database.
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
If strFileType = "something" Then
If Left(tdf.Name, 3) <> "tbe" Then
' do something
End If
Else
If Left(tdf.Name, 3) = "tbe" Then
' do something
End If
End If

hth
 
P

Piet Linden

i'm having syntax problems setting an operator as a variable... any
suggestions would be greatl;y appreciated

If strFileType = ... Then
        strCriteria = "<> "
    Else
        strCriteria = "="
    End If

   ' Loop through all tables in the database.
   Set dbs = CurrentDb
   For Each tdf In dbs.TableDefs
       If Left(tdf.Name, 3) & strCriteria & "tbe" Then
   ...

do it the easy way...
If strFileType = ... Then
if left(tdf.name,3) ="tbe" then
'do one thing
else ' --- the only other alternative!
'do something else
end if
end if
 
M

Mark Kubicki

thanks everybody..
-m.



i'm having syntax problems setting an operator as a variable... any
suggestions would be greatl;y appreciated

If strFileType = ... Then
strCriteria = "<> "
Else
strCriteria = "="
End If

' Loop through all tables in the database.
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
If Left(tdf.Name, 3) & strCriteria & "tbe" Then
...

do it the easy way...
If strFileType = ... Then
if left(tdf.name,3) ="tbe" then
'do one thing
else ' --- the only other alternative!
'do something else
end if
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top