Report - VBA If Then...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gazsharpe101
    New Member
    • Oct 2007
    • 13

    Report - VBA If Then...

    Hi everyone.

    I am working on a report that has a running sum text box throughout the detail section of the report. In the report footer I have a summary in which I have a text box i.e. txtTotal, which has the final total of the running sum box in it. I am setting the txtTotal box to store the Nz value of the running sum, so if it is null, then txtTotal is 0, therefore it will always have a numeric value.

    In VBA on the report format section, I have an IF...Then statement in VBA saying:

    If Me.txtTotal>0 and Me.txtTotal < Then
    Me.txtexample=" example"
    End If

    However, when I run the report, I keep getting an error saying 'Run time error 13 - Type mismatch' and it flags up the line:
    If Me.txtTotal>0 and Me.txtTotal < Then

    But when I hover my cursor over the txtTotal field it says 'txtTotal=0', so my question is why does it enter into this if statement for only when txtTotal is greater than zero, when it is even saying it is equal to zero when I put my cursor on it?

    Thanks.
    Gareth.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi Gareth. If what you have posted is what is in your code you are missing a value after the less than symbol:
    Originally posted by gazsharpe101
    If Me.txtTotal>0 and Me.txtTotal < Then
    Me.txtexample=" example"
    End If
    Placing an X where there should be a number or a variable to compare you should have:
    [code=vb]If Me.txtTotal>0 and Me.txtTotal < X Then
    Me.txtexample=" example"
    End If[/code]
    -Stewart

    Comment

    • gazsharpe101
      New Member
      • Oct 2007
      • 13

      #3
      Thank you for your response.

      I do apologise, it should say '< 7' i must have missed it lol.

      Comment

      Working...