VB programming problem - help!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jjanfish
    New Member
    • Apr 2008
    • 4

    VB programming problem - help!!

    Hi
    I write interactive worksheets for my students using VB programming. If they enter a string of text accurately, then the string turns green - excellent. I don't write from scratch, just copy and paste from an existing document and change the wording of the string. The problem I have is that the first box will work correctly, but most of the subsequent ones, will not recognise the first keystroke, so if they enter 'John likes to eat cake.' it appears as 'ohn likes to eat cake.'
    I include a sample of the code that I use.

    Private Sub TextBox2_Change ()
    If TextBox2.Text = "I like to play computer games." Then TextBox2.ForeCo lor = &H8000& Else TextBox2.ForeCo lor = vbBlack
    End Sub

    Strangely, sometimes this does not happen, but I can see no reason why.

    Jan
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Try to run the code in Lost Focus event instead of Change of the textbox.

    Comment

    • jjanfish
      New Member
      • Apr 2008
      • 4

      #3
      Originally posted by debasisdas
      Try to run the code in Lost Focus event instead of Change of the textbox.

      Would that mean changing all the Change() bits in the code to Lost Focus() ?

      I tried changing one line of the code to that and the text box disappeared and the text did not turn green

      I am confused.

      Comment

      • mafaisal
        New Member
        • Sep 2007
        • 142

        #4
        hello

        Also Try in Validate Event of Textbox

        Faisal

        Originally posted by jjanfish
        Hi
        I write interactive worksheets for my students using VB programming. If they enter a string of text accurately, then the string turns green - excellent. I don't write from scratch, just copy and paste from an existing document and change the wording of the string. The problem I have is that the first box will work correctly, but most of the subsequent ones, will not recognise the first keystroke, so if they enter 'John likes to eat cake.' it appears as 'ohn likes to eat cake.'
        I include a sample of the code that I use.

        Private Sub TextBox2_Change ()
        If TextBox2.Text = "I like to play computer games." Then TextBox2.ForeCo lor = &H8000& Else TextBox2.ForeCo lor = vbBlack
        End Sub

        Strangely, sometimes this does not happen, but I can see no reason why.

        Jan

        Comment

        • jjanfish
          New Member
          • Apr 2008
          • 4

          #5
          Originally posted by mafaisal
          hello

          Also Try in Validate Event of Textbox

          Faisal
          Mafaisal, I'm new to this - a bit more explanation please?

          I've worked out why it works sometimes and not others. I have 3 worksheets in Word, linked by hyperlinks. If only one w/sheet is open it works fine. If more than one are open, only the first box works correctly. Why would this be????

          Comment

          Working...