Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2003
    Posts
    16

    Unanswered: "stepping" through code

    I have a subform on a main form. The subform is a continuous form showing all parts that are a part of the drawing on the main form.
    On the subform I have a control that sums all of the parts on the subform. I reference that control on the subform from my mainform on the "On Current" event. The code is below and "should" make a label visible if the parts are 0 and not visible if the parts are greater than 0. I can step through the code and the label changes visibility as desired, but when I run the code, the label is always visible.

    Private Sub Form_Current()
    If Me!sfrmXLList.Form!SumQTO > 0 Then
    Me.lblRFI.Visible = False
    Else
    Me.lblRFI.Visible = True
    End If
    End Sub

    Can anyone tell me why it will not work correctly when it is "run"?
    Thanks.
    - jc -

  2. #2
    Join Date
    Jun 2002
    Location
    Saudi Arabia / Philippines
    Posts
    126
    jc,

    How are you calculating and displaying the count of drawing objects?
    Rod

    fe_rod@hotmail.com

  3. #3
    Join Date
    Jan 2003
    Posts
    16
    It is a text box (hidden) with this code as the control source.
    =Sum([qtytoorder])
    I have a condensed version zipped (43k) if you are interested.
    I have put in a msgbox function on the if and the else and it ALWAYS evalutes to the qty being greater than zero even though stepping through the code evalutes it correctly.
    Thank you for responding...
    - jc -

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Try
    If Me!sfrmXLList!SumQTO > 0 Then

    End If

  5. #5
    Join Date
    Jun 2002
    Location
    Saudi Arabia / Philippines
    Posts
    126
    jc

    Lurking around in the back of my mind are two thoughts: I'm not sure VBA follows the same sequence of evaluation in break mode as it does in run mode; is it not true that if you test a null value it is always false? So I'm wondering, only wondering mind you, whether when running the code your test occurs before the count and you are testing a null value. That would account for it always jumping to the Else statement.

    So how to test this hypothesis? Try displaying the count with the MsgBox function. If you get an Invalid Use Of Null then we know the reason (not necessarily the solution).

    Alternatively try putting the If..Then...Else back to front. By that I mean making the test <= 0 and swapping the actions. Does it still jump to the Else statement or does it now execute the Then statement. If it executes the Then statement then I suggest the count value is truely zero and we have to put our thinking caps on again.
    Rod

    fe_rod@hotmail.com

  6. #6
    Join Date
    Jan 2003
    Posts
    16
    Quote Originally Posted by hammbakka
    Try
    If Me!sfrmXLList!SumQTO > 0 Then

    End If
    Thanks for your input, hammbakka - I tried what you suggested and got the same results.

    - jc -

  7. #7
    Join Date
    Jan 2003
    Posts
    16
    Rod,
    I tried what you suggested. Reversing the If - Else produced the same results:
    SumQTO evaluated to greater than zero if it was in the 'if' statement and when it was in the 'else' statement.
    I tried printing the results in:
    if Me!sfrmXLList.Form!SumQTO > 0 then
    MsgBox "if" & Str(Me!sfrmXLList.Form!SumQTO)
    else
    MsgBox "if" & Str(Me!sfrmXLList.Form!SumQTO)
    endif

    and that always evaluated to "if 0" and an OK button.
    putting in <= 0 gave me "else 0" and an OK button.

    In order to make this work I have made the On Current in the Parent form to read:
    Dim Sumit as integer
    Sumit = DSum("QtyToOrder","qPrtXLList","Applic = '" & Me.Drawing & "'"
    If Sumit > 0 then
    Me.lblRFI.Visible = False
    Else
    Me.lblRFI.Visible = True
    End If

    And that works! It is almost as if the "=Sum" on the subform is not getting evaluated until some time AFTER the On Current on the Main form is getting processed.
    ????????
    I have it fixed BUT - I REALLY would like to know why the other code would not work. Thanks for all your input and if you do have an answer (or anyone else has an answer) I sure would like to hear about it.

    Thanks again.
    - jc -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •