Re: ComboBox Selection

Tech-Archive recommends: Fix windows errors by optimizing your registry



You will run into problems if your string contains the same character you
are using as a delimiter (the same problem occurs with double quotes). When
that is the case, to get the delimiter character to be taken as a literal
character and not as a delimiter, you need to double it.

Example:
strTest = 'O'Hare'
will fail, but
strTest = 'O''Hare'
will work. That's 2 single quotes, not one double quote. If you then issue
the command
Debug.Print strTest
you will get
O'Hare
in the debug window.

The simplest answer in this situation is to use the Replace function to
change any single quotes in the string to 2 single quotes.

Example:
strlocation = "=' & Chr(34) & Replace(Me.cboLocation.Value, "'", "''") &
Chr(34)'"

This will double up any single quotes that may be in the string so that they
will taken as literal characters and not delimiters.

To test the results, use a Debug.Print statment on the variable, as in the
example above, to see if you're getting the value and syntax desired
assigned to the variable.

--
Wayne Morgan
MS Access MVP


<learning_codes@xxxxxxxxxxx> wrote in message
news:1139970382.036655.92670@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

I am trying to put CHR(34) on the combo box but I did not get any
results. Here is the code that I try to set up. Can you help me if I
did the right thing or did I miss something?

strYear = "='" & Me.cboYear.Value & "'"
strlocation = "=' & Chr(34) & Me.cboLocation.Value & Chr(34)'"
strsport = "=' & Chr(34) & Me.cboSport.Value & Chr(34)'"

DoCmd.SetWarnings False

strFilter = "[Location] " & strLocation & " and [Sport] " &
strSport

I'm only having trouble running the report when I select the name of
the location that has single quoate and also the name of sport that
also has single quaote.

Your feedback would be much appreciated.
Thanks



.



Relevant Pages

  • Re: OpenSSH: spaces in user name
    ... Unruh> quotes and double quotes into my name. ... such a delimiter plays a very particular ... In your case you want it to either be a character in a name, ... humans but even more confusing to the computer. ...
    (comp.security.ssh)
  • Re: Run-Time Error 3061...Too few parameters. Expected 2
    ... I'm getting a run time error. ... I've used single quotes around the value from ... double-quote character instead, or you can use the Replacefunction to ...
    (microsoft.public.access.formscoding)
  • Re: Help with file reads
    ... , or double quotes inside the double quotes, where you use \". ... now there's no terminating " to actually end the string. ... since it clashes with the escape character. ... Use single quotes (most escape sequences aren't translated in single ...
    (alt.php)
  • Re: Handling quotes in data entries
    ... You have the choice of using either single quotes or double quotes ... Since your string has double quotes in it, ... single quotes as the delimiter: ...
    (microsoft.public.access.modulesdaovba)
  • Re: Whats the last argument?
    ... which is OK too even if the quotes are not necessary. ... character and put every variable ... you remove every special meaning to every ... Note that we first get out of single quotes to be able to pass ...
    (comp.unix.shell)