Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

What is Chr(34) ?

Discussion in 'Information Technology' started by Martin, Oct 29, 2005.

Tags:
  1. Martin

    Martin
    Expand Collapse
    Guest

    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)
     
  2. Dirk Goldgar

    Dirk Goldgar
    Expand Collapse
    Guest

    "Martin" <lajitong888@21cn.com> wrote in message
    news:uSBgT0C3FHA.2624@TK2MSFTNGP09.phx.gbl
    > 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)
     
  3. Martin

    Martin
    Expand Collapse
    Guest

    You are tops!

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

    "Dirk Goldgar" <dg@NOdataSPAMgnostics.com> дÈëÏûÏ¢ÐÂÎÅ:Oej$i1E3FHA.3276@TK2MSFTNGP10.phx.gbl...
    > "Martin" <lajitong888@21cn.com> wrote in message
    > news:uSBgT0C3FHA.2624@TK2MSFTNGP09.phx.gbl
    >> 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)
    >
    >
     
  4. Larry Linson

    Larry Linson
    Expand Collapse
    Guest

    "Martin" wrote

    > 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
     

Share This Page