What is Chr(34) ?

M

Martin

Hi! According to the following VBA (written by Dirk), I have two
questions:
1.What's the meaning of Chr(34) ?
2.If later (for example when I get out off this function), I want to make
the filter unavailable(that is, show all the records), How should I write
the VBA sentence?
3. is this OK? -- DoCmd.ApplyFilter , "[customer name]=Martin Lee" ??
-- DoCmd.ApplyFilter , "[customer name]"="Martin Lee" ??


Thanks. And thanks Dirk. :)


Dim strCustomerWanted As String

strCustomerWanted = "Martin Lee"

Docmd.OpenTable "Customer Inf"
DoCmd.ApplyFilter , "[customer name]=" & _
Chr(34) & strCustomerWanted & Chr(34)
 
D

Dirk Goldgar

Martin said:
Hi! According to the following VBA (written by Dirk), I have two
questions:
1.What's the meaning of Chr(34) ?

Did you look up Chr in the help file? You'd probably have to do it in
the VB Editor environment, as that's where the help for VBA and its
functions can be found.

Chr() is a built-in VBA function that returns the character that
corresponds to the numeric value of its argument, using the ASCII coding
scheme. Chr(34) returns the double-quote character, ".
2.If later (for example when I get out off this function), I want to
make the filter unavailable(that is, show all the records), How
should I write the VBA sentence?
DoCmd.ShowAllRecords

3. is this OK? -- DoCmd.ApplyFilter , "[customer name]=Martin Lee"
?? -- DoCmd.ApplyFilter , "[customer name]"="Martin
Lee" ??

Neither of those is OK. The first is a valid string, but you need
quotes of some sort in the filter string surrounding the string value
"Martin Lee". The filter string must evaluate to one of the following
two things:

[customer name]="Martin Lee"

or


[customer name]='Martin Lee'

That is, either single-quotes or double-quotes must be embedded in the
filter string around the literal value you want to compare to [customer
name].

Since some names contain the single-quote/apostrophe character -- for
example, O'Neal -- I prefer to use the double-quote character to
surround name values. However, it's tricky to get that character into a
string literal like this filter string. If you just write ...

DoCmd.ApplyFilter , "[customer name]="Martin Lee""

.... the compiler won't be able to interpret that properly, because it
looks like you have two string literals, "[customer name]=" and "", with
some unknown words (Martin Lee) between them. You can do it by doubling
up the quotes, like this:

DoCmd.ApplyFilter , "[customer name]=""Martin Lee"""

but that's hard to read. So I used the Chr() function to create quote
characters and concatenate them into the string:
DoCmd.ApplyFilter , "[customer name]=" & _
Chr(34) & strCustomerWanted & Chr(34)
 
M

Martin

You are tops!

Thanks Dirk! You are so nice, warmhearted and a top specialist !

Dirk Goldgar said:
Martin said:
Hi! According to the following VBA (written by Dirk), I have two
questions:
1.What's the meaning of Chr(34) ?

Did you look up Chr in the help file? You'd probably have to do it in
the VB Editor environment, as that's where the help for VBA and its
functions can be found.

Chr() is a built-in VBA function that returns the character that
corresponds to the numeric value of its argument, using the ASCII coding
scheme. Chr(34) returns the double-quote character, ".
2.If later (for example when I get out off this function), I want to
make the filter unavailable(that is, show all the records), How
should I write the VBA sentence?
DoCmd.ShowAllRecords

3. is this OK? -- DoCmd.ApplyFilter , "[customer name]=Martin Lee"
?? -- DoCmd.ApplyFilter , "[customer name]"="Martin
Lee" ??

Neither of those is OK. The first is a valid string, but you need
quotes of some sort in the filter string surrounding the string value
"Martin Lee". The filter string must evaluate to one of the following
two things:

[customer name]="Martin Lee"

or


[customer name]='Martin Lee'

That is, either single-quotes or double-quotes must be embedded in the
filter string around the literal value you want to compare to [customer
name].

Since some names contain the single-quote/apostrophe character -- for
example, O'Neal -- I prefer to use the double-quote character to
surround name values. However, it's tricky to get that character into a
string literal like this filter string. If you just write ...

DoCmd.ApplyFilter , "[customer name]="Martin Lee""

... the compiler won't be able to interpret that properly, because it
looks like you have two string literals, "[customer name]=" and "", with
some unknown words (Martin Lee) between them. You can do it by doubling
up the quotes, like this:

DoCmd.ApplyFilter , "[customer name]=""Martin Lee"""

but that's hard to read. So I used the Chr() function to create quote
characters and concatenate them into the string:
DoCmd.ApplyFilter , "[customer name]=" & _
Chr(34) & strCustomerWanted & Chr(34)


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
L

Larry Linson

Thanks Dirk! You are so nice, warmhearted
and a top specialist !

Yes, he is indeed.

But, in keeping with "give a man a fish..., teach him to fish....", let me
add this: to determine what any Chr(xx) represents, open any module, click
View | Immediate Window (back a few versions, this was Debug Window) and
enter:

? Chr(xx)

where xx is the value you want to know about. Any printable character will
appear on the next line. Control characters such as LineFeed or Carriage
Return will not be so obvious.

Larry Linson
Microsoft Access MVP
 

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