none
a CODE QUESTION - LOOP DOESNT END - Checkbox click RRS feed

  • Question

  • I have a problem with a VBA Sub that starts when clicking a checkbox.

    the procedure goes on as an endless loop.

    I wanted to change checkbox on and off when clicking on it.

    What am i doing wrong??

     

    This is the code:

     

    Public Sub AddDeadline_Click()

    If AddDeadline.Value = False Then
        AddDeadline.Value = True
    ElseIf AddDeadline.Value = True Then
        AddDeadline.Value = False
    End If

    End Sub


    Ofir Marco , MCTS P.Z. Projects
    Thursday, December 1, 2011 10:37 AM

All replies

  • Hi Marco,

    I guess you are playing (maybe without your knowledge) with Async events.

    Are you running the AddDeadline_Click() on the OnChanged event of the CheckBox?? If that is true, is normal you are in a loop, your event is called any time you change the value (by Web App or by code).

    Kind Regards


    Miguel Soler
    Thursday, December 1, 2011 11:52 AM
  • Hi Miguel,

    Thanks for the reply.

    I didn't understand what you mean by " OnChanged event of the CheckBox??"

    I have a custom form on VBA with 3 checkbox (it happens to all of them) "AddDeadline" is the name of one of them.

    what i wanted to do is to mark the checkox and to click OK button which runs a few actions on the background.

    I also want to be able to remove the V sign from the checkbox if i click it again...

    But when i click on the checkbox it doesn't work.  when i debug it (Step by step) i see it changes the checkbox value from false to true but then the AddDeadline_Click() starts all over again.

    What is the reason and how should I write the code in order to fix it the way i want? 


    Ofir Marco , MCTS P.Z. Projects
    Thursday, December 1, 2011 12:03 PM
  • Try to debug also the function OnLoad or OnInit of your form. I´m guessing that when you click the button, first is generated the AddDeadline_Click, after your OnLoad or Init, and after that the AddDeadline_Click and is because that everything changes again and again...

    Let me know your results debugging this functions too.

     


    Miguel Soler
    Thursday, December 1, 2011 12:13 PM