Re: Combobox SelectedIndex
can you give an example of 1 of your cmbactiveproj items that contains an apostrophe?
Re: Combobox SelectedIndex
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'
Re: Combobox SelectedIndex
paul is correct. You are calling FindStringExact, then modifying the string causes it to be unexact.
Re: Combobox SelectedIndex
So Do I need to chnage the code?
Re: Combobox SelectedIndex
ok. so your combobox contains:
09_10 - This is a test'
what does txtprojnameupdt contain?
Re: Combobox SelectedIndex
09_10 - This is a test'
Thats what is confusing me
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''
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
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.
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
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.