Results 1 to 13 of 13

Thread: Combobox SelectedIndex

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2009
    Posts
    1,058

    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!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Combobox SelectedIndex

    can you give an example of 1 of your cmbactiveproj items that contains an apostrophe?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2009
    Posts
    1,058

    Re: Combobox SelectedIndex

    09_10 - This is a test'

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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'

  5. #5
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    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

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2009
    Posts
    1,058

    Re: Combobox SelectedIndex

    So Do I need to chnage the code?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Combobox SelectedIndex

    ok. so your combobox contains:

    09_10 - This is a test'

    what does txtprojnameupdt contain?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2009
    Posts
    1,058

    Re: Combobox SelectedIndex

    09_10 - This is a test'

    Thats what is confusing me

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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''

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2009
    Posts
    1,058

    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.

  11. #11
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    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

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2009
    Posts
    1,058

    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.

  13. #13
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    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:
    1. What are you trying to do?
    2. What is it doing?
    3. Show ALL the relevant code you are using (the whole sub if it is small or the section that does a certain task).
    4. Show us where the problem is.
    5. 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
  •  



Click Here to Expand Forum to Full Width