|
-
Aug 13th, 2010, 06:51 AM
#1
Thread Starter
Frenzied Member
Combobox SelectedIndex
Hi,
I have the following code;
Code:
txtprojnameupdt.Text = txtProjname.Text
cmbactiveproj.SelectedIndex = cmbactiveproj.FindStringExact(Replace(txtprojnameupdt.Text, "'", "''"))
This code doesn't reflect the cmbactiveproj.SelectedIndex to display the txtprojnameupdt.Text.
Please anyhelp..
Before I had
Code:
cmbactiveproj.SelectedIndex = cmbactiveproj.FindStringExact.txtprojnameupdt.Text
and it worked fine, but know txtprojnameupdt has a possibility of having apostrophe and hence I had the replace any help pls!
-
Aug 13th, 2010, 07:10 AM
#2
Re: Combobox SelectedIndex
can you give an example of 1 of your cmbactiveproj items that contains an apostrophe?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 13th, 2010, 07:18 AM
#3
Thread Starter
Frenzied Member
Re: Combobox SelectedIndex
-
Aug 13th, 2010, 07:23 AM
#4
Re: Combobox SelectedIndex
that has only 1 apostrophe in it, so replacing 1 apostrophe with 2 apostrophe's would be:
09_10 - This is a test''
when your combobox actually contains:
09_10 - This is a test'
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 13th, 2010, 08:02 AM
#5
Re: Combobox SelectedIndex
paul is correct. You are calling FindStringExact, then modifying the string causes it to be unexact.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Aug 13th, 2010, 08:46 AM
#6
Thread Starter
Frenzied Member
Re: Combobox SelectedIndex
So Do I need to chnage the code?
-
Aug 13th, 2010, 08:51 AM
#7
Re: Combobox SelectedIndex
ok. so your combobox contains:
09_10 - This is a test'
what does txtprojnameupdt contain?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 13th, 2010, 09:05 AM
#8
Thread Starter
Frenzied Member
Re: Combobox SelectedIndex
09_10 - This is a test'
Thats what is confusing me
-
Aug 13th, 2010, 09:08 AM
#9
Re: Combobox SelectedIndex
09_10 - This is a test'
+ then you're replacing a single ' with 2 ' so findstringexact is searching for:
09_10 - This is a test''
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 13th, 2010, 10:19 AM
#10
Thread Starter
Frenzied Member
Re: Combobox SelectedIndex
Ok Changed it to ;
Code:
txtprojnameupdt.Text = Replace(txtProjname.Text, "'", "'")
Me.QryactiveprojectsTableAdapter.Fill(Me.Projstatus.qryactiveprojects)
cmbactiveproj.SelectedIndex = cmbactiveproj.FindStringExact(txtprojnameupdt.Text)
Then I had a txtprojname.text = 4567 - test app changed to 4567 - test app'.
The value of cmbactiveproj, txtprojname and txtprojnameupdt is identical i.e., 4567 - test app'.
However, an error message is prompted as shown below -
Unclosed quotation mark after the character string '4567 - test app''. Incorrect syntax near '4567 - test app''.
When you click ok, the whole form is populated fine. Why do I receive this error? Thanks
Last edited by dr223; Aug 13th, 2010 at 10:22 AM.
-
Aug 13th, 2010, 10:44 AM
#11
Re: Combobox SelectedIndex
If you want to pass a string to a database you can't use single quotes. If you want single quotes in the string you must double them up. That's why you get the error.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Aug 13th, 2010, 10:51 AM
#12
Thread Starter
Frenzied Member
Re: Combobox SelectedIndex
Ok,
Changed to
Code:
txtprojnameupdt.Text = Replace(txtProjname.Text, "'", "''")
4567 - test app became 4567 - test app'' - notice two apostrophes instead of one.
The error disappeared, but
txtprojname is empty and cmbactiveproj.Selectedindex is not working as it shows the first project not the updated project i.e., 4567 - test app'. Any help please
Last edited by dr223; Aug 13th, 2010 at 10:55 AM.
-
Aug 13th, 2010, 11:00 AM
#13
Re: Combobox SelectedIndex
You have to figure out what you want to do then tell us. Just putting random peices of code in your app won't help you and neither will supplying an error without the information around it:
- What are you trying to do?
- What is it doing?
- Show ALL the relevant code you are using (the whole sub if it is small or the section that does a certain task).
- Show us where the problem is.
- Tell us what you already tried.
When you supply a limited amount of information its like calling the mechanic, telling them your car doesn't sound right and asking them how you can fix it. The first thing they will tell you is to bring it down. So bring your code down, not a single line, that is not helpful.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|