Welcome to SPN

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

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

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?
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page