Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Apr 2008
    Location
    Jacksonville, North Carolina, USA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    command buttons (2003)

    Good Morning all. My question today is, is there a way to use a command button to run a formula linking it to a certian field inside a form

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: command buttons (2003)

    What would you want to do with the formula? Display the result in a message box, or store the value in a text box, or ...

  3. #3
    Lounger
    Join Date
    Apr 2008
    Location
    Jacksonville, North Carolina, USA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: command buttons (2003)

    Ex I have total as a field on a form but it doesn't need to be calculated everytime you goto that form so i need a button so that when that total is need they can click it and it will calculate the other fields to give me a total in the total field. so i think its the result in a message box. Thank you again Hans for your efforts.

    Matt

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: command buttons (2003)

    Your reply is a bit ambiguous, so I'll give a few general examples. If you would like more help, please provide detailed and specific information.

    All examples assume that you have placed a command button named cmdTotal on the form.

    1) You want to display the sum of fields FieldA, FieldB and FieldC. The On Click event procedure for the button is

    Private Sub cmdTotal_Click()
    MsgBox Nz(Me.FieldA, 0) + Nz(Me.FieldB, 0) + Nz(Me.FieldC, 0), vbInformation
    End Sub

    2) You want to store the sum of fields FieldA, FieldB and FieldC in a field named FieldTotal.

    Private Sub cmdTotal_Click()
    Me.FieldTotal = Nz(Me.FieldA, 0) + Nz(Me.FieldB, 0) + Nz(Me.FieldC, 0)
    End Sub

    Note: in general, you shouldn't store calculated results in a table. It's better to use a query to perform the calculations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •