MS Access: Using the IIf Function in a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry

    MS Access: Using the IIf Function in a form

    Hello,
    I am designing a form and need to know how to get a Check Box(PASS)to
    automatically update when the data in a Text Box (MARK), in the same
    form, is >=24.
    Using the Event dialogue box for the Check Box, AfterUpdate, I have
    tried:
    IIf([MARK]>=24,True,False )
    Also:
    IIf([MARK]>=24,1,0)
    Also:
    IIf([MARK]>=24,"Yes","No" )

    Although I get no error messages, nothing seems to work.
    Any suggestions?
  • Michael Barg

    #2
    Re: MS Access: Using the IIf Function in a form

    "Terry" <tclarke@mersey mail.com> schrieb im Newsbeitrag
    news:388ec0af.0 311220906.626dd c59@posting.goo gle.com...[color=blue]
    > Hello,
    > I am designing a form and need to know how to get a Check Box(PASS)to
    > automatically update when the data in a Text Box (MARK), in the same
    > form, is >=24.
    > Using the Event dialogue box for the Check Box, AfterUpdate, I have
    > tried:
    > IIf([MARK]>=24,True,False )
    > Also:
    > IIf([MARK]>=24,1,0)
    > Also:
    > IIf([MARK]>=24,"Yes","No" )
    >
    > Although I get no error messages, nothing seems to work.
    > Any suggestions?[/color]

    Hi Terry,

    Use the After Update Edvent of the TextBox to set PASS
    Something like:

    IIf ... Me.PASS=True

    Viel Erfolg,
    Michael


    Comment

    • Phil Stanton

      #3
      Re: MS Access: Using the IIf Function in a form

      You need this for the update and a similar sub for OnCurrent of Form.
      It's nothing to do with what you key into the checkbox. This should be
      locked anyway



      Private Sub MARK_AfterUpdat e()

      If MARK >= Then
      Pass = True
      Else
      Pass = False
      End If

      End Sub

      Phil


      "Terry" <tclarke@mersey mail.com> wrote in message
      news:388ec0af.0 311220906.626dd c59@posting.goo gle.com...[color=blue]
      > Hello,
      > I am designing a form and need to know how to get a Check Box(PASS)to
      > automatically update when the data in a Text Box (MARK), in the same
      > form, is >=24.
      > Using the Event dialogue box for the Check Box, AfterUpdate, I have
      > tried:
      > IIf([MARK]>=24,True,False )
      > Also:
      > IIf([MARK]>=24,1,0)
      > Also:
      > IIf([MARK]>=24,"Yes","No" )
      >
      > Although I get no error messages, nothing seems to work.
      > Any suggestions?[/color]


      Comment

      • Terry

        #4
        Re: MS Access: Using the IIf Function in a form

        I put the sub into Afterupdate Event in the Mark control box and
        although I get no error messages....not hing happens.
        I couldn't put the sub in the OnCurrent of the form as I don't know
        how to do this...did try help but found it much too complex to
        understand. Is there an easy explanation of how to do this?

        Terry

        "Phil Stanton" <phil@stantonfa mily.co.uk> wrote in message news:<3fbf9e7f$ 0$62652$65c6931 4@mercury.nildr am.net>...[color=blue]
        > You need this for the update and a similar sub for OnCurrent of Form.
        > It's nothing to do with what you key into the checkbox. This should be
        > locked anyway
        >
        >
        >
        > Private Sub MARK_AfterUpdat e()
        >
        > If MARK >= Then
        > Pass = True
        > Else
        > Pass = False
        > End If
        >
        > End Sub
        >
        > Phil
        >
        >
        > "Terry" <tclarke@mersey mail.com> wrote in message
        > news:388ec0af.0 311220906.626dd c59@posting.goo gle.com...[color=green]
        > > Hello,
        > > I am designing a form and need to know how to get a Check Box(PASS)to
        > > automatically update when the data in a Text Box (MARK), in the same
        > > form, is >=24.
        > > Using the Event dialogue box for the Check Box, AfterUpdate, I have
        > > tried:
        > > IIf([MARK]>=24,True,False )
        > > Also:
        > > IIf([MARK]>=24,1,0)
        > > Also:
        > > IIf([MARK]>=24,"Yes","No" )
        > >
        > > Although I get no error messages, nothing seems to work.
        > > Any suggestions?[/color][/color]

        Comment

        • Phil Stanton

          #5
          Re: MS Access: Using the IIf Function in a form

          What version of Access are you using

          Phil
          "Terry" <tclarke@mersey mail.com> wrote in message
          news:388ec0af.0 311221553.5fdcd 15a@posting.goo gle.com...[color=blue]
          > I put the sub into Afterupdate Event in the Mark control box and
          > although I get no error messages....not hing happens.
          > I couldn't put the sub in the OnCurrent of the form as I don't know
          > how to do this...did try help but found it much too complex to
          > understand. Is there an easy explanation of how to do this?
          >
          > Terry
          >
          > "Phil Stanton" <phil@stantonfa mily.co.uk> wrote in message[/color]
          news:<3fbf9e7f$ 0$62652$65c6931 4@mercury.nildr am.net>...[color=blue][color=green]
          > > You need this for the update and a similar sub for OnCurrent of Form.
          > > It's nothing to do with what you key into the checkbox. This should be
          > > locked anyway
          > >
          > >
          > >
          > > Private Sub MARK_AfterUpdat e()
          > >
          > > If MARK >= Then
          > > Pass = True
          > > Else
          > > Pass = False
          > > End If
          > >
          > > End Sub
          > >
          > > Phil
          > >
          > >
          > > "Terry" <tclarke@mersey mail.com> wrote in message
          > > news:388ec0af.0 311220906.626dd c59@posting.goo gle.com...[color=darkred]
          > > > Hello,
          > > > I am designing a form and need to know how to get a Check Box(PASS)to
          > > > automatically update when the data in a Text Box (MARK), in the same
          > > > form, is >=24.
          > > > Using the Event dialogue box for the Check Box, AfterUpdate, I have
          > > > tried:
          > > > IIf([MARK]>=24,True,False )
          > > > Also:
          > > > IIf([MARK]>=24,1,0)
          > > > Also:
          > > > IIf([MARK]>=24,"Yes","No" )
          > > >
          > > > Although I get no error messages, nothing seems to work.
          > > > Any suggestions?[/color][/color][/color]


          Comment

          • Peter Russell

            #6
            Re: MS Access: Using the IIf Function in a form

            Phil Stanton previously wrote:
            [color=blue]
            > Private Sub MARK_AfterUpdat e()
            >[/color]
            If me.MARK >= XXXXX Then 'what?
            me.Pass = True[color=blue]
            > Else
            > me.Pass = False
            > End If
            >
            > End Sub[/color]

            Regards

            Peter Russell

            Comment

            • Jim Allensworth

              #7
              Re: MS Access: Using the IIf Function in a form

              On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), rusty@127.0.0.1
              (Peter Russell) wrote:
              [color=blue]
              >Phil Stanton previously wrote:
              >[color=green]
              >> Private Sub MARK_AfterUpdat e()
              >>[/color]
              > If me.MARK >= XXXXX Then 'what?
              > me.Pass = True[color=green]
              >> Else
              >> me.Pass = False
              >> End If
              >>
              >> End Sub[/color]
              >[/color]
              Or simply...
              Private Sub MARK_AfterUpdat e()
              Me.PASS = Me.MARK >= 24
              End Sub

              - Jim

              Comment

              • Jim Allensworth

                #8
                Re: MS Access: Using the IIf Function in a form

                Terry, I'm wondering if you tried what I suggested in your other post
                on this subject. Perhaps my instructions were not sufficiently clear.

                At any rate consider what *event* you want to trigger this checking of
                the check box. Then apply the code there.

                - Jim

                On 22 Nov 2003 15:53:44 -0800, tclarke@merseym ail.com (Terry) wrote:
                [color=blue]
                >I put the sub into Afterupdate Event in the Mark control box and
                >although I get no error messages....not hing happens.
                >I couldn't put the sub in the OnCurrent of the form as I don't know
                >how to do this...did try help but found it much too complex to
                >understand. Is there an easy explanation of how to do this?
                >
                >Terry
                >
                >"Phil Stanton" <phil@stantonfa mily.co.uk> wrote in message news:<3fbf9e7f$ 0$62652$65c6931 4@mercury.nildr am.net>...[color=green]
                >> You need this for the update and a similar sub for OnCurrent of Form.
                >> It's nothing to do with what you key into the checkbox. This should be
                >> locked anyway
                >>
                >>
                >>
                >> Private Sub MARK_AfterUpdat e()
                >>
                >> If MARK >= Then
                >> Pass = True
                >> Else
                >> Pass = False
                >> End If
                >>
                >> End Sub
                >>
                >> Phil
                >>
                >>
                >> "Terry" <tclarke@mersey mail.com> wrote in message
                >> news:388ec0af.0 311220906.626dd c59@posting.goo gle.com...[color=darkred]
                >> > Hello,
                >> > I am designing a form and need to know how to get a Check Box(PASS)to
                >> > automatically update when the data in a Text Box (MARK), in the same
                >> > form, is >=24.
                >> > Using the Event dialogue box for the Check Box, AfterUpdate, I have
                >> > tried:
                >> > IIf([MARK]>=24,True,False )
                >> > Also:
                >> > IIf([MARK]>=24,1,0)
                >> > Also:
                >> > IIf([MARK]>=24,"Yes","No" )
                >> >
                >> > Although I get no error messages, nothing seems to work.
                >> > Any suggestions?[/color][/color][/color]

                Comment

                • Phil Stanton

                  #9
                  Re: MS Access: Using the IIf Function in a form

                  Nay, Lad

                  The event should be triggered after he puts the mark in. The check box
                  basically is a pass or fail.

                  Possibly the problem is that it is a textbox and the 24 is being regarded as
                  a string rather than a number.

                  So use instaed ow what I suggested

                  Private Sub MARK_AfterUpdat e()

                  If CSng(MARK) >= 24 Then ' This converts it to single number
                  with decimals
                  Pass = True
                  Else
                  Pass = False
                  End If

                  End Sub

                  If you have the form in Design View and click on the small square at the
                  top left of the form you should see the form's properties. If you can't, on
                  the top menubar, click View then Properties.
                  When you have the property box open, select the Events Tab. The top event is
                  On Current#
                  Key in [ yes a square bracket which the will become [Event Procedure]. At
                  the right end of the line are 3 dots which when you press will open up the
                  VBA module.
                  It will already say

                  Private Sub Form_Current()

                  End Sub

                  so key in or copy and paste

                  If CSng(MARK) >= 24 Then ' This converts it to single number
                  with decimals
                  Pass = True
                  Else
                  Pass = False
                  End If

                  between the Private "Sub Form_Current()" and "End Sub"

                  Do the same thing by clicking on your MARK box

                  Phil

                  "Jim Allensworth" <JimNOT@NOTdata centricsolution s.com> wrote in message
                  news:3fc0d86e.8 86421@netnews.c omcast.net...[color=blue]
                  > Terry, I'm wondering if you tried what I suggested in your other post
                  > on this subject. Perhaps my instructions were not sufficiently clear.
                  >
                  > At any rate consider what *event* you want to trigger this checking of
                  > the check box. Then apply the code there.
                  >
                  > - Jim
                  >
                  > On 22 Nov 2003 15:53:44 -0800, tclarke@merseym ail.com (Terry) wrote:
                  >[color=green]
                  > >I put the sub into Afterupdate Event in the Mark control box and
                  > >although I get no error messages....not hing happens.
                  > >I couldn't put the sub in the OnCurrent of the form as I don't know
                  > >how to do this...did try help but found it much too complex to
                  > >understand. Is there an easy explanation of how to do this?
                  > >
                  > >Terry
                  > >
                  > >"Phil Stanton" <phil@stantonfa mily.co.uk> wrote in message[/color][/color]
                  news:<3fbf9e7f$ 0$62652$65c6931 4@mercury.nildr am.net>...[color=blue][color=green][color=darkred]
                  > >> You need this for the update and a similar sub for OnCurrent of Form.
                  > >> It's nothing to do with what you key into the checkbox. This should be
                  > >> locked anyway
                  > >>
                  > >>
                  > >>
                  > >> Private Sub MARK_AfterUpdat e()
                  > >>
                  > >> If MARK >= Then
                  > >> Pass = True
                  > >> Else
                  > >> Pass = False
                  > >> End If
                  > >>
                  > >> End Sub
                  > >>
                  > >> Phil
                  > >>
                  > >>
                  > >> "Terry" <tclarke@mersey mail.com> wrote in message
                  > >> news:388ec0af.0 311220906.626dd c59@posting.goo gle.com...
                  > >> > Hello,
                  > >> > I am designing a form and need to know how to get a Check Box(PASS)to
                  > >> > automatically update when the data in a Text Box (MARK), in the same
                  > >> > form, is >=24.
                  > >> > Using the Event dialogue box for the Check Box, AfterUpdate, I have
                  > >> > tried:
                  > >> > IIf([MARK]>=24,True,False )
                  > >> > Also:
                  > >> > IIf([MARK]>=24,1,0)
                  > >> > Also:
                  > >> > IIf([MARK]>=24,"Yes","No" )
                  > >> >
                  > >> > Although I get no error messages, nothing seems to work.
                  > >> > Any suggestions?[/color][/color]
                  >[/color]


                  Comment

                  • Jim Allensworth

                    #10
                    Re: MS Access: Using the IIf Function in a form

                    On Sun, 23 Nov 2003 16:37:59 -0000, "Phil Stanton"
                    <phil@stantonfa mily.co.uk> wrote:
                    [color=blue]
                    >Nay, Lad[/color]
                    Lad? It's obvious you don't know me at all. ;-)
                    [color=blue]
                    >
                    >The event should be triggered after he puts the mark in. The check box
                    >basically is a pass or fail.
                    >
                    >Possibly the problem is that it is a textbox and the 24 is being regarded as
                    >a string rather than a number.[/color]
                    A textbox doesn't care what it holds: numbers, strings, calculations,
                    special characters, etc. That has no relevance to the issue.
                    [color=blue]
                    >
                    >So use instaed ow what I suggested
                    >
                    >Private Sub MARK_AfterUpdat e()
                    >
                    > If CSng(MARK) >= 24 Then ' This converts it to single number
                    >with decimals
                    > Pass = True
                    > Else
                    > Pass = False
                    > End If
                    >
                    >End Sub
                    >[/color]
                    You are too verbose - code wise. This will do what is needed

                    Me.PASS = Me.MARK >= 24

                    It could be placed in the forms On Current as well as the MARK After
                    Update. Although if it is a dataentry form then it is only needed for
                    the textbox.

                    - Jim

                    Comment

                    • Terry

                      #11
                      Re: MS Access: Using the IIf Function in a form

                      JimNOT@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message news:<3fc0d77a. 642500@netnews. comcast.net>...[color=blue]
                      > On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), rusty@127.0.0.1
                      > (Peter Russell) wrote:
                      >[color=green]
                      > >Phil Stanton previously wrote:
                      > >[color=darkred]
                      > >> Private Sub MARK_AfterUpdat e()
                      > >>[/color]
                      > > If me.MARK >= XXXXX Then 'what?
                      > > me.Pass = True[color=darkred]
                      > >> Else
                      > >> me.Pass = False
                      > >> End If
                      > >>
                      > >> End Sub[/color]
                      > >[/color]
                      > Or simply...
                      > Private Sub MARK_AfterUpdat e()
                      > Me.PASS = Me.MARK >= 24
                      > End Sub
                      >
                      > - Jim[/color]

                      Jim, Tried this one first:

                      Private Sub Mark_AfterUpdat e()
                      If Me.MARK >= 24 Then
                      Me.Pass = True
                      Else
                      Me.Pass = False
                      End If
                      End Sub

                      This had no effect and showed no errors. So I tried the second one as follows:

                      Private Sub Mark_AfterUpdat e()
                      Me.Pass = Me.Mark >= 24
                      End Sub

                      Didn't get anything when I tried it out on the form, but when I closed
                      the form I got a runtime error '2113' "The value you have entered
                      isn't valid for this field" ....I clicked the Debug button. This
                      brought me back to the VBA code and the line:

                      Me.Pass = Me.Mark >= 24

                      was highlighted in yellow, with a yellow arrow to the left.

                      This has thrown me altogether as I couldn't find out how to actually
                      debug.

                      In the database I'm creating, I have made a relationship between the
                      "Student Details" table and the "Exam details" table so that I have a
                      single form with some fields from each table.

                      The Student Details Section Is at the top of the form, i.e ID, Name &
                      Location, and the Exam details are sort of embedded into this form in
                      the bottom half.

                      This means that a subform also exists for Exam details. I thought this
                      might have some baring on the result and placed the code in both the
                      form and the subform but the result is exactly the same.

                      Comment

                      • Phil Stanton

                        #12
                        Re: MS Access: Using the IIf Function in a form

                        Four things, Terry

                        1) At the top of the code window you should have the 2 lines
                        Option Compare Database
                        Option Explicit

                        Then there will be a faint line line

                        2) After you have keyed in the VBA Code are you going to Menu bar at the
                        top and selecting
                        Debug -> Compile XXXXXXX(Your project name)
                        This checks the syntax of your code, but not it's logic

                        3) On the properties box, if you select the All option, the Name of the
                        controls in question must be
                        "MARK" and "Pass" without the inverted commas

                        4) On the properties box, if you select the Event option
                        does the Form On Current have [Event Procedure] beside it
                        and
                        does the Text Box named MARK have [Event Procedure] beside it

                        Phil

                        "Terry" <tclarke@mersey mail.com> wrote in message
                        news:388ec0af.0 311231149.7226c 116@posting.goo gle.com...[color=blue]
                        > JimNOT@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message[/color]
                        news:<3fc0d77a. 642500@netnews. comcast.net>...[color=blue][color=green]
                        > > On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), rusty@127.0.0.1
                        > > (Peter Russell) wrote:
                        > >[color=darkred]
                        > > >Phil Stanton previously wrote:
                        > > >
                        > > >> Private Sub MARK_AfterUpdat e()
                        > > >>
                        > > > If me.MARK >= XXXXX Then 'what?
                        > > > me.Pass = True
                        > > >> Else
                        > > >> me.Pass = False
                        > > >> End If
                        > > >>
                        > > >> End Sub
                        > > >[/color]
                        > > Or simply...
                        > > Private Sub MARK_AfterUpdat e()
                        > > Me.PASS = Me.MARK >= 24
                        > > End Sub
                        > >
                        > > - Jim[/color]
                        >
                        > Jim, Tried this one first:
                        >
                        > Private Sub Mark_AfterUpdat e()
                        > If Me.MARK >= 24 Then
                        > Me.Pass = True
                        > Else
                        > Me.Pass = False
                        > End If
                        > End Sub
                        >
                        > This had no effect and showed no errors. So I tried the second one as[/color]
                        follows:[color=blue]
                        >
                        > Private Sub Mark_AfterUpdat e()
                        > Me.Pass = Me.Mark >= 24
                        > End Sub
                        >
                        > Didn't get anything when I tried it out on the form, but when I closed
                        > the form I got a runtime error '2113' "The value you have entered
                        > isn't valid for this field" ....I clicked the Debug button. This
                        > brought me back to the VBA code and the line:
                        >
                        > Me.Pass = Me.Mark >= 24
                        >
                        > was highlighted in yellow, with a yellow arrow to the left.
                        >
                        > This has thrown me altogether as I couldn't find out how to actually
                        > debug.
                        >
                        > In the database I'm creating, I have made a relationship between the
                        > "Student Details" table and the "Exam details" table so that I have a
                        > single form with some fields from each table.
                        >
                        > The Student Details Section Is at the top of the form, i.e ID, Name &
                        > Location, and the Exam details are sort of embedded into this form in
                        > the bottom half.
                        >
                        > This means that a subform also exists for Exam details. I thought this
                        > might have some baring on the result and placed the code in both the
                        > form and the subform but the result is exactly the same.[/color]


                        Comment

                        • Terry

                          #13
                          Re: MS Access: Using the IIf Function in a form

                          tclarke@merseym ail.com (Terry) wrote in message news:<388ec0af. 0311231149.7226 c116@posting.go ogle.com>...[color=blue]
                          > JimNOT@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message news:<3fc0d77a. 642500@netnews. comcast.net>...[color=green]
                          > > On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), rusty@127.0.0.1
                          > > (Peter Russell) wrote:
                          > >[color=darkred]
                          > > >Phil Stanton previously wrote:
                          > > >
                          > > >> Private Sub MARK_AfterUpdat e()
                          > > >>
                          > > > If me.MARK >= XXXXX Then 'what?
                          > > > me.Pass = True
                          > > >> Else
                          > > >> me.Pass = False
                          > > >> End If
                          > > >>
                          > > >> End Sub
                          > > >[/color]
                          > > Or simply...
                          > > Private Sub MARK_AfterUpdat e()
                          > > Me.PASS = Me.MARK >= 24
                          > > End Sub
                          > >
                          > > - Jim[/color]
                          >
                          > Jim, Tried this one first:
                          >
                          > Private Sub Mark_AfterUpdat e()
                          > If Me.MARK >= 24 Then
                          > Me.Pass = True
                          > Else
                          > Me.Pass = False
                          > End If
                          > End Sub
                          >
                          > This had no effect and showed no errors. So I tried the second one as follows:
                          >
                          > Private Sub Mark_AfterUpdat e()
                          > Me.Pass = Me.Mark >= 24
                          > End Sub
                          >
                          > Didn't get anything when I tried it out on the form, but when I closed
                          > the form I got a runtime error '2113' "The value you have entered
                          > isn't valid for this field" ....I clicked the Debug button. This
                          > brought me back to the VBA code and the line:
                          >
                          > Me.Pass = Me.Mark >= 24
                          >
                          > was highlighted in yellow, with a yellow arrow to the left.
                          >
                          > This has thrown me altogether as I couldn't find out how to actually
                          > debug.
                          >
                          > In the database I'm creating, I have made a relationship between the
                          > "Student Details" table and the "Exam details" table so that I have a
                          > single form with some fields from each table.
                          >
                          > The Student Details Section Is at the top of the form, i.e ID, Name &
                          > Location, and the Exam details are sort of embedded into this form in
                          > the bottom half.
                          >
                          > This means that a subform also exists for Exam details. I thought this
                          > might have some baring on the result and placed the code in both the
                          > form and the subform but the result is exactly the same.[/color]

                          UPDATE!

                          I discovered that the Check Box actually had the wrong name. When I
                          looked at the Check Box Name in it's properties I found it had been
                          given the default name of Check20, so I changed it and the code works,
                          up to a point, I'll get to that later.

                          I also need to do the same with another Check Box, Resit, from the
                          same control so I put in extra code as follows:

                          Private Sub Mark_AfterUpdat e()

                          If Me.Mark >= 24 Then
                          Me.Pass = True
                          Me.Resit = False
                          Else
                          Me.Pass = False
                          Me.Resit = True
                          End If

                          End Sub

                          And this works also, up to a point. The point being that I need to set
                          the two Check Boxes Pass & Resit if I have no data in the Mark Text
                          Box, which is by the way set to Number Double Datatype. This doesn't
                          happen if I delete the data from the Mark Box, the Check Boxes remain
                          ticked.
                          I tried creating a new sub as follows:

                          Private Sub Mark_AfterUpdat e()

                          If Me.Mark >= IsNull Then
                          Me.Pass = False
                          Me.Resit = False
                          End If

                          End Sub

                          But this created a compile error. Is there any way I can do this?

                          Terry

                          Comment

                          • Douglas J. Steele

                            #14
                            Re: MS Access: Using the IIf Function in a form

                            Private Sub Mark_AfterUpdat e()

                            If IsNull(Me.Mark) Then
                            Me.Pass = False
                            Me.Resit = False
                            Else
                            Me.Pass = (Me.Mark >= 24)
                            Me.Resit = Not Me.Pass
                            End If

                            End Sub


                            --
                            Doug Steele, Microsoft Access MVP

                            (No private e-mails, please)



                            "Terry" <tclarke@mersey mail.com> wrote in message
                            news:388ec0af.0 311231533.3b54e 81c@posting.goo gle.com...[color=blue]
                            > tclarke@merseym ail.com (Terry) wrote in message[/color]
                            news:<388ec0af. 0311231149.7226 c116@posting.go ogle.com>...[color=blue][color=green]
                            > > JimNOT@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message[/color][/color]
                            news:<3fc0d77a. 642500@netnews. comcast.net>...[color=blue][color=green][color=darkred]
                            > > > On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), rusty@127.0.0.1
                            > > > (Peter Russell) wrote:
                            > > >
                            > > > >Phil Stanton previously wrote:
                            > > > >
                            > > > >> Private Sub MARK_AfterUpdat e()
                            > > > >>
                            > > > > If me.MARK >= XXXXX Then 'what?
                            > > > > me.Pass = True
                            > > > >> Else
                            > > > >> me.Pass = False
                            > > > >> End If
                            > > > >>
                            > > > >> End Sub
                            > > > >
                            > > > Or simply...
                            > > > Private Sub MARK_AfterUpdat e()
                            > > > Me.PASS = Me.MARK >= 24
                            > > > End Sub
                            > > >
                            > > > - Jim[/color]
                            > >
                            > > Jim, Tried this one first:
                            > >
                            > > Private Sub Mark_AfterUpdat e()
                            > > If Me.MARK >= 24 Then
                            > > Me.Pass = True
                            > > Else
                            > > Me.Pass = False
                            > > End If
                            > > End Sub
                            > >
                            > > This had no effect and showed no errors. So I tried the second one as[/color][/color]
                            follows:[color=blue][color=green]
                            > >
                            > > Private Sub Mark_AfterUpdat e()
                            > > Me.Pass = Me.Mark >= 24
                            > > End Sub
                            > >
                            > > Didn't get anything when I tried it out on the form, but when I closed
                            > > the form I got a runtime error '2113' "The value you have entered
                            > > isn't valid for this field" ....I clicked the Debug button. This
                            > > brought me back to the VBA code and the line:
                            > >
                            > > Me.Pass = Me.Mark >= 24
                            > >
                            > > was highlighted in yellow, with a yellow arrow to the left.
                            > >
                            > > This has thrown me altogether as I couldn't find out how to actually
                            > > debug.
                            > >
                            > > In the database I'm creating, I have made a relationship between the
                            > > "Student Details" table and the "Exam details" table so that I have a
                            > > single form with some fields from each table.
                            > >
                            > > The Student Details Section Is at the top of the form, i.e ID, Name &
                            > > Location, and the Exam details are sort of embedded into this form in
                            > > the bottom half.
                            > >
                            > > This means that a subform also exists for Exam details. I thought this
                            > > might have some baring on the result and placed the code in both the
                            > > form and the subform but the result is exactly the same.[/color]
                            >
                            > UPDATE!
                            >
                            > I discovered that the Check Box actually had the wrong name. When I
                            > looked at the Check Box Name in it's properties I found it had been
                            > given the default name of Check20, so I changed it and the code works,
                            > up to a point, I'll get to that later.
                            >
                            > I also need to do the same with another Check Box, Resit, from the
                            > same control so I put in extra code as follows:
                            >
                            > Private Sub Mark_AfterUpdat e()
                            >
                            > If Me.Mark >= 24 Then
                            > Me.Pass = True
                            > Me.Resit = False
                            > Else
                            > Me.Pass = False
                            > Me.Resit = True
                            > End If
                            >
                            > End Sub
                            >
                            > And this works also, up to a point. The point being that I need to set
                            > the two Check Boxes Pass & Resit if I have no data in the Mark Text
                            > Box, which is by the way set to Number Double Datatype. This doesn't
                            > happen if I delete the data from the Mark Box, the Check Boxes remain
                            > ticked.
                            > I tried creating a new sub as follows:
                            >
                            > Private Sub Mark_AfterUpdat e()
                            >
                            > If Me.Mark >= IsNull Then
                            > Me.Pass = False
                            > Me.Resit = False
                            > End If
                            >
                            > End Sub
                            >
                            > But this created a compile error. Is there any way I can do this?
                            >
                            > Terry[/color]


                            Comment

                            • Terry

                              #15
                              Re: MS Access: Using the IIf Function in a form

                              Thanks Doug, Jim & Phil,

                              I have used Doug's code, very impressive, and now have no problems:

                              Private Sub Mark_AfterUpdat e()[color=blue]
                              >
                              > If IsNull(Me.Mark) Then
                              > Me.Pass = False
                              > Me.Resit = False
                              > Else
                              > Me.Pass = (Me.Mark >= 24)
                              > Me.Resit = Not Me.Pass
                              > End If
                              >
                              > End Sub[/color]

                              In conclusion, my problem began because I didn't verify the name of my
                              Check Box as Pass, which the debugger didn't pick up on, hence no
                              error messages. Once this was corrected everything was OK.
                              Thanks for all your help.

                              Comment

                              Working...