Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How would I test for quoted value in if statement. "=" 1

Status
Not open for further replies.

Pack10

Programmer
Feb 3, 2010
495
US
I have a query that checks fields for the following value "=" -- its looking for not only the dash, but the quotes as well --- so
each field in the query has something like this....IIf([Field1] <> """=""" or [Field1] = "=",1,0) and then I have an update query that
will add fields with the 1 and update a field in the table with the total. The update is [Field1] + [Field2] + [Field3] ..... then i want to update a numeric field with this value. Its close, but I am NOT FILTERING the value that is the quote and the = sign....

How would i write the IIf statement to bypass the field if it has "=" or = as values.....
 
With the instr function or the like operator. Instr returns 0 if there is no match.
 
Thats an interesting way to do it
How do you handle a double quoted test
Like "=" i want to test for the whole value not only
The equ sign
 
Code:
Dim str As String

str = """="""
[green]
'''Just the = sign
'If InStr(str, "=") Then
'    str = Replace(str, "=", "")
'End If

''' = sign with " around it[/green]
If InStr(str, Chr(34) & "=" & Chr(34)) Then
    str = Replace(str, Chr(34) & "=" & Chr(34), "")
End If

Debug.Print str

Have fun.

---- Andy
 
Double quotes embed in strings the same way...

Some would use single quote delimited strings in queries or you can double the doulbe quotes so either of the below are valid...

Like [red]'[/red]"="[red]'[/red]
Like [red]"[/red]""=""[red]"[/red]

I tend to use double quote delimited strings that way I don't have to figure out how many to count or where one character begins or not and it is consistent in VBA that only supports double quoted strings.

The arguement on the other side is that in vba you have fewer string delimeters to doulbe up for queries when embedding single quotes and if you move to a database Server most likely it will use single quoted strings anyway.

If my eyes didn't play tricks on me from fierce astigmatisms I probably would lead to single quote delimeted.... To each his own on which is better. Some also like to embed the chr(34) like Andy did in code. I'd stay away from that method in queries in case you do want to convert to a database server and end up with a non-ASCII text datatype.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top