Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Newbie VBA code help

Discussion in 'Information Technology' started by Adam@nospam.com, Jul 28, 2006.

  1. Adam@nospam.com

    Adam@nospam.com
    Expand Collapse
    Guest

    Hi All,

    I'm slowly learn VBA and have tried to enter in the following code to a
    form. However its not working with handling errors, like if one of the
    fields is Null.

    ====================================================

    Private Sub Team_AfterUpdate()

    If Me.AuditScore = "" Then
    Me.AuditScore = 0
    Else
    If Me.Team = "Correspondence 1" Or Me.Team = "Correspondence 2" Then
    Dim Corra As Double
    Dim CTotal As Double

    Corra = Me.AuditScore + Me.AttendanceActual + Me.PunctualityActual +
    Me.TeamworkActual + Me.AWLAchieved + Me.ATRecontactsAchieved
    CTotal = Corra / 6
    Me.Text108 = CTotal

    ElseIf Me.Team = "COMMS" Then
    Dim Comms As Double
    Dim commstotal As Double
    Me.Text108 = commstotal / 4

    End If

    End If

    End Sub


    ====================================================

    Could someone please tell me where I'm going wrong?

    I think its to do with the first second and if the AuditScore field is
    empty...

    Many Thanks

    Adam
     
  2. Loading...

    Similar Threads Forum Date
    Newbie here, just wanted to introduce myself Interfaith Dialogues Jan 18, 2005

  3. MH

    MH
    Expand Collapse
    Guest

    Try:

    If IsNull(Me.AuditScore) Then ...

    There is a very big difference between a null value and an empty string in
    programming, the empty string is known, it's just empty whereas the null
    value is unknown so has to be checked for explicitly. That's why when you
    are designing a query your syntax has to take nulls into account i.e. ...

    ="" or Is Null

    ....To return empty strings and nulls

    Hope this clears it up for you

    MH

    "Adam@nospam.com" <adamevans81@gmail.com> wrote in message
    news:1148234171.153928.184300@y43g2000cwc.googlegroups.com...
    > Hi All,
    >
    > I'm slowly learn VBA and have tried to enter in the following code to a
    > form. However its not working with handling errors, like if one of the
    > fields is Null.
    >
    > ====================================================
    >
    > Private Sub Team_AfterUpdate()
    >
    > If Me.AuditScore = "" Then
    > Me.AuditScore = 0
    > Else
    > If Me.Team = "Correspondence 1" Or Me.Team = "Correspondence 2" Then
    > Dim Corra As Double
    > Dim CTotal As Double
    >
    > Corra = Me.AuditScore + Me.AttendanceActual + Me.PunctualityActual +
    > Me.TeamworkActual + Me.AWLAchieved + Me.ATRecontactsAchieved
    > CTotal = Corra / 6
    > Me.Text108 = CTotal
    >
    > ElseIf Me.Team = "COMMS" Then
    > Dim Comms As Double
    > Dim commstotal As Double
    > Me.Text108 = commstotal / 4
    >
    > End If
    >
    > End If
    >
    > End Sub
    >
    >
    > ====================================================
    >
    > Could someone please tell me where I'm going wrong?
    >
    > I think its to do with the first second and if the AuditScore field is
    > empty...
    >
    > Many Thanks
    >
    > Adam
    >
     
  4. Adam@nospam.com

    Adam@nospam.com
    Expand Collapse
    Guest

    Yes that works thank you.

    Are there any error commands that might be useful for me to know?
     

Share This Page