Re: ComboBox Selection
- From: "Wayne Morgan" <comprev_gothroughthenewsgroup@xxxxxxxxxxx>
- Date: Tue, 14 Feb 2006 21:02:24 -0600
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
.
- Follow-Ups:
- Re: ComboBox Selection
- From: learning_codes@xxxxxxxxxxx
- Re: ComboBox Selection
- References:
- ComboBox Selection
- From: learning_codes@xxxxxxxxxxx
- ComboBox Selection
- Prev by Date: Re: forms and printing
- Next by Date: Re: Data Testing To Prevent Saving Bad Data
- Previous by thread: ComboBox Selection
- Next by thread: Re: ComboBox Selection
- Index(es):
Relevant Pages
|