Basic Form/Event Question

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

    #1

    Basic Form/Event Question

    Dear group users,

    There are three columns of type "Currency" which are represented in a
    form by three text boxes. When I type a numeric value in text box 1, I
    would like value*2 to display automatically in text box 2 and value*3 to
    display in text box 3.

    I mingled with the events of these fields, but I cannot seem to get the
    right lexicon for Microsoft Access; I get no data or error returned.

    Thank you for your help,
    Max
  • Wayne Gillespie

    #2
    Re: Basic Form/Event Question

    On Fri, 24 Mar 2006 09:18:14 -0500, Max Plante <Maxime.Plante+ usenet@gmail.co m>
    wrote:
    [color=blue]
    >Dear group users,
    >
    >There are three columns of type "Currency" which are represented in a
    >form by three text boxes. When I type a numeric value in text box 1, I
    >would like value*2 to display automatically in text box 2 and value*3 to
    >display in text box 3.
    >
    >I mingled with the events of these fields, but I cannot seem to get the
    >right lexicon for Microsoft Access; I get no data or error returned.
    >
    >Thank you for your help,
    >Max[/color]

    In the AfterUpdate event of TextBox1 put -

    Me.TextBox2 = Nz(Me.TextBox1) *2
    Me.TextBox3 = Nz(Me.TextBox1) *3

    Change the names to suit your controls.


    Wayne Gillespie
    Gosford NSW Australia

    Comment

    • Wayne Morgan

      #3
      Re: Basic Form/Event Question

      If all of 3 of these values are in one record, you may want to try a 3
      column combo box instead. The first visible column would be displayed in the
      textbox portion of the combo box after selection. The other 2 columns could
      be displayed in the adjacent 2 textboxes by setting their Control Source to
      the appropriate column of the combo box.

      Example:
      =[cboMyCombo].[Column](1)
      and
      =[cboMyCombo].[Column](2)

      The Column property is zero based, so 1 is the second column, 2 is the
      third, etc.

      --
      Wayne Morgan
      MS Access MVP


      "Max Plante" <Maxime.Plante+ usenet@gmail.co m> wrote in message
      news:4423fee0$0 $26965$ed362ca5 @nr1.newsreader .com...[color=blue]
      > Dear group users,
      >
      > There are three columns of type "Currency" which are represented in a form
      > by three text boxes. When I type a numeric value in text box 1, I would
      > like value*2 to display automatically in text box 2 and value*3 to display
      > in text box 3.
      >
      > I mingled with the events of these fields, but I cannot seem to get the
      > right lexicon for Microsoft Access; I get no data or error returned.
      >
      > Thank you for your help,
      > Max[/color]


      Comment

      • Wayne Morgan

        #4
        Re: Basic Form/Event Question

        PS,

        I think I misunderstood what you were trying to do. Yes, if you just want to
        put multiplied values in the other fields, then Wayne Gillespie has given
        the correct answer. However, if that is all you're doing, why? Unless you
        just want that as a "default" that you may change, then the value can be
        calculated whenever you need it and shouldn't be stored in the table.

        --
        Wayne Morgan
        MS Access MVP


        Comment

        • Max Plante

          #5
          Re: Basic Form/Event Question

          Thank you for your help, but my interpretation of it must be wrong, as I
          cannot accomplish this simple equation.

          When I enter:
          Me.textBox2=Nz( Me.textBox1)*2
          in the "After Update" field of textBox1, Access returns the error:
          "Microsoft Office Access can't find the macro 'Me.'"

          1) Is "Me." by any chance the equivalent of "this", in JavaScript? If
          not, what is "Me."?

          2) If "Me." must be translated for my application, by the name of which
          element should it be replaced?

          Thank you again,
          Max

          Wayne Gillespie wrote:[color=blue]
          > On Fri, 24 Mar 2006 09:18:14 -0500, Max Plante <Maxime.Plante+ usenet@gmail.co m>
          > wrote:
          >
          >[color=green]
          >>Dear group users,
          >>
          >>There are three columns of type "Currency" which are represented in a
          >>form by three text boxes. When I type a numeric value in text box 1, I
          >>would like value*2 to display automatically in text box 2 and value*3 to
          >>display in text box 3.
          >>
          >>I mingled with the events of these fields, but I cannot seem to get the
          >>right lexicon for Microsoft Access; I get no data or error returned.
          >>
          >>Thank you for your help,
          >>Max[/color]
          >
          >
          > In the AfterUpdate event of TextBox1 put -
          >
          > Me.TextBox2 = Nz(Me.TextBox1) *2
          > Me.TextBox3 = Nz(Me.TextBox1) *3
          >
          > Change the names to suit your controls.
          >
          >
          > Wayne Gillespie
          > Gosford NSW Australia[/color]

          Comment

          • David W. Fenton

            #6
            Re: Basic Form/Event Question

            Max Plante <Maxime.Plante+ usenet@gmail.co m> wrote in
            news:44244d1b$0 $26927$ed362ca5 @nr1.newsreader .com:
            [color=blue]
            > When I enter:
            > Me.textBox2=Nz( Me.textBox1)*2
            > in the "After Update" field of textBox1, Access returns the error:
            > "Microsoft Office Access can't find the macro 'Me.'"
            >
            > 1) Is "Me." by any chance the equivalent of "this", in JavaScript?
            > If not, what is "Me."?
            >
            > 2) If "Me." must be translated for my application, by the name of
            > which element should it be replaced?[/color]

            What Wayne gave you is VBA code and should be typed in the code
            window for the AfterUpdate event.

            Or, you could just set the ControlSource of the other controls to:

            =Nz([textBox1],0)*2

            But that's only if you're using these fields for display. If you've
            bound them to fields in your recordsource, you'll need to actually
            update them if you want to store the calculations.

            Of course, there are only a few situations where one should be
            storing such calculations. It's not clear if yours is one of them or
            not.

            --
            David W. Fenton http://www.dfenton.com/
            usenet at dfenton dot com http://www.dfenton.com/DFA/

            Comment

            • Wayne Morgan

              #7
              Re: Basic Form/Event Question

              In the form's Properties Events tab, set the AfterUpdate to [Event
              Procedure] and click the ... button that appears to the right of the box.
              Enter the code in the window that opens.

              Example:
              Private Sub textBox1_AfterU pdate()
              Me.textBox2 = Nz(Me.textBox1) * 2
              End Sub

              The code as listed above will change textBox2 to 0 if you clear textBox1. If
              you want clearing textBox1 to also clear textBox2, then remove the Nz()
              function.

              Example:
              Me.textBox2 = Me.textBox1 * 2

              --
              Wayne Morgan
              MS Access MVP


              "Max Plante" <Maxime.Plante+ usenet@gmail.co m> wrote in message
              news:44244d1b$0 $26927$ed362ca5 @nr1.newsreader .com...[color=blue]
              > Thank you for your help, but my interpretation of it must be wrong, as I
              > cannot accomplish this simple equation.
              >
              > When I enter:
              > Me.textBox2=Nz( Me.textBox1)*2
              > in the "After Update" field of textBox1, Access returns the error:
              > "Microsoft Office Access can't find the macro 'Me.'"
              >
              > 1) Is "Me." by any chance the equivalent of "this", in JavaScript? If not,
              > what is "Me."?
              >
              > 2) If "Me." must be translated for my application, by the name of which
              > element should it be replaced?
              >
              > Thank you again,
              > Max
              >
              > Wayne Gillespie wrote:[color=green]
              >> On Fri, 24 Mar 2006 09:18:14 -0500, Max Plante
              >> <Maxime.Plante+ usenet@gmail.co m>
              >> wrote:
              >>
              >>[color=darkred]
              >>>Dear group users,
              >>>
              >>>There are three columns of type "Currency" which are represented in a
              >>>form by three text boxes. When I type a numeric value in text box 1, I
              >>>would like value*2 to display automatically in text box 2 and value*3 to
              >>>display in text box 3.
              >>>
              >>>I mingled with the events of these fields, but I cannot seem to get the
              >>>right lexicon for Microsoft Access; I get no data or error returned.
              >>>
              >>>Thank you for your help,
              >>>Max[/color]
              >>
              >>
              >> In the AfterUpdate event of TextBox1 put -
              >>
              >> Me.TextBox2 = Nz(Me.TextBox1) *2
              >> Me.TextBox3 = Nz(Me.TextBox1) *3
              >>
              >> Change the names to suit your controls.
              >>
              >>
              >> Wayne Gillespie
              >> Gosford NSW Australia[/color][/color]


              Comment

              • Max Plante

                #8
                Re: Basic Form/Event Question

                Thank you Wayne,
                Thank you David,

                This first peak into the VBA universe is rather interesting. Everything
                works now!

                Max


                Wayne Morgan wrote:[color=blue]
                > In the form's Properties Events tab, set the AfterUpdate to [Event
                > Procedure] and click the ... button that appears to the right of the box.
                > Enter the code in the window that opens.
                >
                > Example:
                > Private Sub textBox1_AfterU pdate()
                > Me.textBox2 = Nz(Me.textBox1) * 2
                > End Sub
                >
                > The code as listed above will change textBox2 to 0 if you clear textBox1. If
                > you want clearing textBox1 to also clear textBox2, then remove the Nz()
                > function.
                >
                > Example:
                > Me.textBox2 = Me.textBox1 * 2
                >[/color]

                Comment

                Working...