Results 1 to 7 of 7

Thread: calculate field

  1. #1
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133

    Unanswered: calculate field

    Problem :
    I have a form bound to a table. One of the textboxes is bound to a field that is formatted as a Double.

    So, normally, you need to enter in that textbox a numeric value, or it will not be accepted.

    I now get the question of some users if there is no possibility to enter in that textbox a formula so that the result of that formula is taken into account.
    Example : if you should enter
    =15+5
    the entry into the field should be 20

    I've tried to solve it with the Before Update event, but Access checks the type of entry before this event is triggered.

    Anyone some bright ideas?

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: calculate field

    Originally posted by Herman
    Problem :
    I have a form bound to a table. One of the textboxes is bound to a field that is formatted as a Double.

    So, normally, you need to enter in that textbox a numeric value, or it will not be accepted.

    I now get the question of some users if there is no possibility to enter in that textbox a formula so that the result of that formula is taken into account.
    Example : if you should enter
    =15+5
    the entry into the field should be 20

    I've tried to solve it with the Before Update event, but Access checks the type of entry before this event is triggered.

    Anyone some bright ideas?
    Do you REALLY want to write a parser and expression evaluator in Access? You're really opening up a can of worms ...

  3. #3
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    No I don't want to....

    My clients are "requesting" it....

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Well 1st off you'll need to make the textbox accept any text ... No numeric restriction. How complex of an expression can be entered? THat will determine how "anal" you'll have to be with the algorithm ...

  5. #5
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    That's exactly the problem : I can't make the textbox to accept text, it's bound to a field in an external table on which I have no saying...

    What I had in mind :
    -open a small dialog box by double clicking the textbox.
    -in that dialogbox, the user can enter his expression
    -on clicking OK button, the expression the user entered in the dialog box should be calculated and the result copied into the original textbox as a numeric value.

    Problem is, I have no idea how to write a function that evaluates the expression and returns a correct result.

    You don't have by any chance such a function?

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by Herman
    That's exactly the problem : I can't make the textbox to accept text, it's bound to a field in an external table on which I have no saying...

    What I had in mind :
    -open a small dialog box by double clicking the textbox.
    -in that dialogbox, the user can enter his expression
    -on clicking OK button, the expression the user entered in the dialog box should be calculated and the result copied into the original textbox as a numeric value.

    Problem is, I have no idea how to write a function that evaluates the expression and returns a correct result.

    You don't have by any chance such a function?
    Wrongo! Check either the Format or Input Mask properties of the textbox control itself ...

    Yes I do. Not here. Written in C++ ... And its recursive ... What kinds of expressions do you anticipate having to evaluate?

    If it's real simple like A+B than can be handled quite easily ...

  7. #7
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    Well, the kind of expressions...

    Let's say we'll allow only straight forward calculations (so nothing fancy as roots etc..)
    I don't think I'll allow parenthesis either.

Posting Permissions

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